Uncatchable AbortError when using shortcut methods
See original GitHub issueHi 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:
- Created 3 years ago
- Reactions:1
- Comments:5 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks for the report. This will be fixed in the next release.
Hoping to find time to fix this and some other issues towards the end of the year.