question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Uncatchable AbortError when using shortcut methods

See original GitHub issue

Hi there 👋

I’m using the shortcut methods to add data to a store. One of the things I want to do is prevent double-adds on the same index. I have the following code to do it:

Live example: https://stackblitz.com/edit/typescript-gxz95r Code:

import { openDB } from "idb";

async function demo() {
  const dbName = "random-db-" + Math.random();
  const storeName = "store-name";
  // Open IDB and create store of unconfirmed txs
  const db = await openDB(dbName, 1, {
    upgrade(db) {
      const store = db.createObjectStore(storeName, {
        keyPath: "idb_t",
        autoIncrement: true
      });
      store.createIndex("idb_t", "idb_t", {
        unique: true
      });
    }
  });

  // add an item
  await db.add(storeName, { idb_t: 1 });

  // add it again
  try {
    await db.add(storeName, { idb_t: 1 });
  } catch (e) {
    // do nothing, this looks like the index preventing a double insert.
    // his still leaves an DOMException: AbortError thrown in the console
  }
}

demo();

If you open the console, there will be an Uncaught (in promise) DOMException: AbortError error.

Reading through the docs for this error, it looks like I’d have to add a handler on the transaction itself. But since the shortcut method handles that for me, I don’t think I can do that.

Is there a way to still use the shortcut methods and also catch AbortError?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jakearchibaldcommented, Jan 6, 2021

Thanks for the report. This will be fixed in the next release.

1reaction
jakearchibaldcommented, Oct 25, 2020

Hoping to find time to fix this and some other issues towards the end of the year.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Encourage use of AbortError for cancellation? #927 - GitHub
Jake is suggesting a way for signals to "throw if cancelled" and ... assertNotAborted(); // throws the Abort Error with message "user left ......
Read more >
Unhandled Rejection (AbortError): The operation was aborted
From MSDN: Note: When abort() is called, the fetch() promise rejects with an Error of type DOMException, with name AbortError.
Read more >
Source: jQuery v1.4.4 - Ben Alman
Behaves like an Array's method, not like a jQuery method. push: push, ... See if we can take a shortcut and just use...
Read more >
The complete guide to AbortController in Node.js
The AbortController API in Node.js is a wonderful new development - learn all about it in this comprehensive tutorial.
Read more >
strix - Add the event API and UI - Brian C. Lane
+ // Since version 1.3, DOM methods and functions like alert + // aren't ... exists allows + // the code to shortcut...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found