diff --git a/src/adapters/browser-transfer/resumable-upload/indexeddb-checkpoint-store.ts b/src/adapters/browser-transfer/resumable-upload/indexeddb-checkpoint-store.ts index f17a62f1..084936d6 100644 --- a/src/adapters/browser-transfer/resumable-upload/indexeddb-checkpoint-store.ts +++ b/src/adapters/browser-transfer/resumable-upload/indexeddb-checkpoint-store.ts @@ -14,7 +14,7 @@ import { isBrowserDataFailureCode } from "../../../application/ports/browser-fil import { browserDataFailure, browserDataSuccess, - mapBrowserDataException, + mapIndexedDbException, } from "../../browser-file-storage/result.ts"; import { snapshotAbortTimers } from "../../platform/abortable-operation.ts"; import { @@ -81,7 +81,7 @@ type ScopeBinding = Readonly<{ }>; /** - * `browserDataFailure` and `mapBrowserDataException` build a `Result`, while the + * `browserDataFailure` and `mapIndexedDbException` build a `Result`, while the * kernel's `translate` contract wants the failure on its own. Both only ever * build the failure arm, so the branch below is a narrowing, not a claim. */ @@ -103,7 +103,7 @@ function checkpointFailure( } function mappedFailure(error: unknown): BrowserDataFailure { - return failureOf(mapBrowserDataException(error, OPERATION)); + return failureOf(mapIndexedDbException(error, OPERATION)); } /** @@ -120,11 +120,9 @@ function admissionFailure(detail: unknown): BrowserDataFailure | null { } /** - * BT-UP-03. The checkpoint store keeps its own failure table rather than the - * `mapIndexedDbException` the other three IndexedDB adapters share: the same - * native error is a different answer here (a `ConstraintError` recovers by - * REOPEN, a quota failure is retryable), and unifying the four tables is a - * separate change from moving the mechanics onto the kernel. + * BT-UP-03. Native exceptions go through `mapIndexedDbException`, the one + * IndexedDB table the other IndexedDB adapters use (F-1, 05-11). Only the + * kernel causes below keep checkpoint-specific answers. */ const translate: IndexedDbTranslate = (cause) => { switch (cause.kind) { diff --git a/tests/unit/resumable-upload-checkpoint.test.ts b/tests/unit/resumable-upload-checkpoint.test.ts index e96c8906..ba8b4572 100644 --- a/tests/unit/resumable-upload-checkpoint.test.ts +++ b/tests/unit/resumable-upload-checkpoint.test.ts @@ -7,6 +7,7 @@ import { createIndexedDbResumableUploadCheckpointStore, uploadCheckpointDatabaseName, } from "../../src/adapters/browser-transfer/resumable-upload/indexeddb-checkpoint-store.ts"; +import { mapIndexedDbException } from "../../src/adapters/browser-file-storage/result.ts"; import { MemoryIndexedDbFactory } from "../helpers/memory-indexeddb.ts"; const scope = Object.freeze({ @@ -514,6 +515,37 @@ describe("IndexedDB resumable upload checkpoint", () => { }); }); + // F-1 (05-11). The store maps native errors with the one IndexedDB table, so + // a missing store is a schema problem and a quota failure is not retried. + it("maps native request errors with the shared IndexedDB table", async () => { + for (const name of [ + "ConstraintError", + "NotFoundError", + "QuotaExceededError", + "InvalidStateError", + "UnknownError", + "SecurityError", + ]) { + const scripted = scriptedFactory(); + const store = createIndexedDbResumableUploadCheckpointStore({ + scope, + factory: scripted.factory, + }); + const pending = store.read("upload_key_01"); + const transaction = await openedCheckpointTransaction(scripted); + const read = transaction.requests[0]; + if (!read) throw new Error("the checkpoint read queued no request"); + const error = new DOMException("native detail", name); + + read.error = error; + read.onerror?.(new Event("error")); + + expect(await pending).toEqual( + mapIndexedDbException(error, "UPLOAD_RECONCILE"), + ); + } + }); + // CP-4. The transaction can already be durably committed while its completion // event is still queued, which is when `abort()` throws. Claiming the abort // would report a committed checkpoint as ABORTED.