-
Notifications
You must be signed in to change notification settings - Fork 149
Description
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
abortmethod 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
errorevent bubbles to the transaction (because the request's parent is the transaction). After theerrorevent is done, it aborts the transaction, which setsIDBTransaction.errorand fires the transaction'sabortevent.setcauses its promise to be rejected on either anerrorevent (which may bubble from the request) or anabortevent (see here and here). Since theerrorevent fires first and does not setIDBTransaction.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).