Skip to content

Surface actual IDB errors instead of raw error events - #81

Merged
Thomas Tay (thomastay) merged 5 commits into
microsoft:masterfrom
mlaw-:master
Apr 14, 2026
Merged

Surface actual IDB errors instead of raw error events#81
Thomas Tay (thomastay) merged 5 commits into
microsoft:masterfrom
mlaw-:master

Conversation

@mlaw-

@mlaw- mlaw- commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

Previously, when an IndexedDB operation failed, callers received the raw
IDBRequest error event rather than the underlying DOMException. This made
error type detection awkward — callers had to navigate err.target.error.name
instead of simply checking err.name or err instanceof DOMException.

Changes

WrapRequest — rejects with req.error (the DOMException) instead of the raw
event. Falls back to the event only if req.error is null.

Transaction onerror/onabort — passes this._trans.error directly to
transactionFailed rather than building a string from it, so the real
DOMException propagates through the transaction's completion promise.

TransactionLockHelper.transactionFailed — accepts string | Error so typed
error objects pass through unchanged.

open() error handler — updated to work with the DOMException directly:
VersionError detection uses err instanceof DOMException && err.name === "VersionError" instead of inspecting event properties; UpgradeCallback error
fields now populate from err.name/err.message.

Result

Callers can now detect specific IDB errors:

try {
await transaction.put("store", item);
} catch (err) {
if (err instanceof DOMException && err.name === "QuotaExceededError") {
// handle quota exceeded
}
}

Tests

  • WrapRequest rejects with the actual DOMException (not the event)
  • WrapRequest falls back to the raw event when req.error is null
  • put propagates the DOMException to the caller

Comment thread src/IndexedDbProvider.ts Outdated
Comment thread src/IndexedDbProvider.ts Outdated
Comment thread src/IndexedDbProvider.ts Outdated

@thomastay Thomas Tay (thomastay) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@thomastay
Thomas Tay (thomastay) merged commit d113496 into microsoft:master Apr 14, 2026
2 checks passed
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