Skip to content

Surface actual IDB errors instead of raw error events#81

Open
mlaw- wants to merge 4 commits intomicrosoft:masterfrom
mlaw-:master
Open

Surface actual IDB errors instead of raw error events#81
mlaw- wants to merge 4 commits intomicrosoft:masterfrom
mlaw-:master

Conversation

@mlaw-
Copy link
Copy Markdown

@mlaw- mlaw- commented Apr 1, 2026

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

eliranek1
eliranek1 previously approved these changes Apr 3, 2026
eliranek1
eliranek1 previously approved these changes Apr 3, 2026
history.join(",")
this._trans.error ??
new Error(
"IndexedDbTransaction Aborted, History: " + history.join(",")
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.

I don't see the this._trans.error.name here?

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