Skip to content

Conversation

@joshkel
Copy link

@joshkel joshkel commented Jun 23, 2023

idb-keyval reported IDBTransaction.error if a set operation failed. However, based on my reading of the IndexedDB spec, and based on testing, IDBTransaction.error may not be set at the time the error event fires. This can be seen under the following scenarios:

  • If IDBObjectStore.add fails because a key already exists
  • If a quota is exceeded in Safari
  • If the transaction is aborted immediately after an IndexedDB operation is requested

The error event's EventTarget should give the specific IDBRequest that failed, and that IDBRequest's error property should always be populated, so accessing event.target should fix this issue.

I tried using a similar approach for abort events, but it did not work; strangely, the abort event's target appears to be the IDBOpenRequest associated with the transaction, rather than the transaction itself, so it does not have a usable error property.

This PR also adds limited unit tests to cover this scenario. Aborting a transaction immediately after issuing a database request appears to be a good way to force an error.

Fixes #163

idb-keyval reported IDBTransaction.error if a `set` operation failed.  However, based on my reading of the IndexedDB spec, and based on testing, IDBTransaction.error may not be set at the time the `error` event fires. This can be seen under the following scenarios:

- If IDBObjectStore.add fails because a key already exists
- If a quota is exceeded in Safari
- If the transaction is aborted immediately after an IndexedDB operation is requested

The `error` event's EventTarget should give the specific IDBRequest that failed, and that IDBRequest's error property should always be populated, so accessing `event.target` should fix this issue.

I tried using a similar approach for `abort` events, but it did not work; strangely, the abort event's target appears to be the IDBOpenRequest associated with the transaction, rather than the transaction itself, so it does not have a usable error property.

This PR also adds limited unit tests to cover this scenario. Aborting a transaction immediately after issuing a database request appears to be a good way to force an error.

Fixes jakearchibald#163
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.

set rejects with null- possible bug in error handling

1 participant