Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error handling #164

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Commits on Jun 23, 2023

  1. Improve error handling

    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
    joshkel committed Jun 23, 2023
    Configuration menu
    Copy the full SHA
    8e8f68f View commit details
    Browse the repository at this point in the history