Files
workinf_Blender_Wasm/web/protocol/archive-extraction-recovery.ts
mes123456 380cbed4ff
Some checks are pending
M6 deployable RC / quick (push) Waiting to run
M6 deployable RC / chromium (push) Blocked by required conditions
M6 deployable RC / release (push) Blocked by required conditions
Checkpoint web parity through Chromium input tasks
2026-08-19 10:39:03 -04:00

51 lines
2.1 KiB
TypeScript

import type { ErrorCode } from "./error";
import {
ArchiveExtractionError,
runArchiveExtractionTransaction as runArchiveExtractionTransactionBase,
type ArchiveExtractionEntryReader,
type ArchiveExtractionReceiptIR,
type ArchiveExtractionStorage,
} from "./archive-extraction-transaction";
export type ArchiveExtractionResourceFaultCode = Extract<ErrorCode, "STORAGE_QUOTA" | "WASM_OUT_OF_MEMORY">;
/** Maps platform-specific allocation failures to the stable archive error contract. */
export function archiveExtractionResourceFaultCode(error: unknown): ArchiveExtractionResourceFaultCode | undefined {
if (typeof error !== "object" || error === null) return undefined;
const candidate = error as { code?: unknown; name?: unknown; message?: unknown };
if (candidate.code === "STORAGE_QUOTA" || candidate.code === "WASM_OUT_OF_MEMORY") return candidate.code;
if (candidate.name === "QuotaExceededError" || candidate.name === "NotEnoughSpaceError") return "STORAGE_QUOTA";
if (candidate.name === "OutOfMemoryError") return "WASM_OUT_OF_MEMORY";
if (candidate.name === "RangeError" && typeof candidate.message === "string" && /out[ -]?of[ -]?memory|oom/i.test(candidate.message)) {
return "WASM_OUT_OF_MEMORY";
}
return undefined;
}
/**
* Runs the existing atomic extraction transaction and normalizes resource failures only after
* the base transaction has removed staging and revalidated the committed identity.
*/
export async function runArchiveExtractionTransaction(
value: unknown,
storage: ArchiveExtractionStorage,
readEntry: ArchiveExtractionEntryReader,
signal: AbortSignal,
): Promise<ArchiveExtractionReceiptIR> {
try {
return await runArchiveExtractionTransactionBase(value, storage, readEntry, signal);
}
catch (error) {
const code = archiveExtractionResourceFaultCode(error);
if (code) throw new ArchiveExtractionError(code, "archive extraction released staging after a resource fault");
throw error;
}
}
export type {
ArchiveExtractionEntryIR,
ArchiveExtractionRequestIR,
ArchiveExtractionReceiptIR,
ArchiveExtractionStorage,
} from "./archive-extraction-transaction";