Skip to content

set rejects with null- possible bug in error handling #163

@joshkel

Description

@joshkel

We've occasionally seen calls to set fail with a null error. I'd like to know why set calls are failing, so I'm trying to figure out what can cause this.

From reading the specs and experimenting, I believe that null may happen under the following circumstances:

  • The transaction's abort method is called. Since idb-keyval doesn't expose its transaction object, this seems unlikely, but maybe it could happen if, e.g., the web page is reloaded in mid-write? (I don't have a deep understanding of how web APIs handle things like page reloads.)

  • A request error occurs. If I understand correctly, a request's error event bubbles to the transaction (because the request's parent is the transaction). After the error event is done, it aborts the transaction, which sets IDBTransaction.error and fires the transaction's abort event.

    set causes its promise to be rejected on either an error event (which may bubble from the request) or an abort event (see here and here). Since the error event fires first and does not set IDBTransaction.error, a request error causes the promise to be rejected without the error being available.

Are you aware of other circumstances that may cause a null rejection?

Can you update idb-keyval to expose the error if the request fails?

See https://codesandbox.io/s/serene-danilo-lseiit?file=/src/index.js for a demonstration. It looks like a transaction's error event could get the error details via event.target.error (although that doesn't fit as well with idb-keyval's as-small-as-possible goal).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions