Skip to content

Conversation

@Hitulya
Copy link

@Hitulya Hitulya commented Feb 28, 2025

Related to #326

Added error checking for the underlying IDBRequest from the event target, fixing generic 'AbortError' throwing. Added separate 'abort' event handler that fires when a transaction is aborted without causing an error within the transaction or its underlying requests.

@mtoac
Copy link

mtoac commented Aug 12, 2025

Do we have a plan to merge this change? Has high probability to get AbortError on iOS

@masonicboom
Copy link

masonicboom commented Nov 5, 2025

I think what's going on is this:

const tx = db.transaction(storeName, "readwrite");
// idb immediately sets up abort handler at https://github.com/jakearchibald/idb/blob/main/src/wrap-idb-value.ts#L91.

const store = tx.objectStore("s");
await store.put(val);

// User backgrounds the app.
// iOS aborts the transaction (https://bugs.webkit.org/show_bug.cgi?id=202705).
// tx.done abort handler fires (https://github.com/jakearchibald/idb/blob/main/src/wrap-idb-value.ts#L86).
// This becomes an unhandled promise rejection, because we haven't reached the next line yet.

await tx.done;

To reproduce, try something like this:

try {
  const tx = db.transaction(storeName, "readwrite");
  const store = tx.objectStore("s");
  await store.add({ id: 1 });
  await store.add({ id: 1 ); // Intentionally cause a constraint failure.
  await tx.done;
} catch (err) {
  console.error("Caught", err);
}

In addition to the console.error message, you should also see an unhandled promise rejection, because the tx.done promise rejected due to the constraint failure, and this happened prior to await tx.done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants