fix(browser-transfer): map checkpoint store IndexedDB errors with the shared table (F-1, 05-11)
The checkpoint store still used the File/Cache table, so a missing store read as NOT_FOUND and a quota failure as retryable. It now uses mapIndexedDbException, leaving one IndexedDB exception table in the repo. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
4358ced65b
commit
3aacbd94da
@@ -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<BrowserDataFailure> = (cause) => {
|
||||
switch (cause.kind) {
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user