diff --git a/src/adapters/storage/browser-storage-adapter.ts b/src/adapters/storage/browser-storage-adapter.ts index 8c240fb5..9f009636 100644 --- a/src/adapters/storage/browser-storage-adapter.ts +++ b/src/adapters/storage/browser-storage-adapter.ts @@ -377,6 +377,9 @@ function recordStorageFailure( cause === "QUOTA_EXCEEDED" ? "STORAGE_QUOTA_EXCEEDED" : "STORAGE_UNAVAILABLE", + // 05-02. error_kind folds three causes into STORAGE_UNAVAILABLE; the + // cause tells a corrupt or oversized value apart from no storage. + reason: cause, }, }); } catch { diff --git a/tests/unit/storage-registry.test.ts b/tests/unit/storage-registry.test.ts index 33f980db..7259492e 100644 --- a/tests/unit/storage-registry.test.ts +++ b/tests/unit/storage-registry.test.ts @@ -269,6 +269,7 @@ describe("storage registry", () => { context: { operation: "write:COLOR_SCHEME", error_kind: "STORAGE_QUOTA_EXCEEDED", + reason: "QUOTA_EXCEEDED", }, }); expect(JSON.stringify(record.mock.calls)).not.toContain("dark"); @@ -307,7 +308,7 @@ describe("storage registry", () => { }); it.each([ - ["malformed JSON", "{private malformed value"], + ["malformed JSON", "{private malformed value", "VALUE_REJECTED"], [ "invalid envelope", JSON.stringify({ @@ -316,11 +317,12 @@ describe("storage registry", () => { value: "dark", unexpected: "private", }), + "VALUE_REJECTED", ], - ["oversized record", "x".repeat(512)], + ["oversized record", "x".repeat(512), "SIZE_LIMIT_EXCEEDED"], ])( "removes a %s once and suppresses it when native cleanup fails", - (_label, raw) => { + (_label, raw, reason) => { const physicalKey = STORAGE_REGISTRY.COLOR_SCHEME.physicalKey; const { storage, getItem, removeItem } = createStorage({ initial: { [physicalKey]: raw }, @@ -343,6 +345,16 @@ describe("storage registry", () => { }); expect(getItem).toHaveBeenCalledOnce(); expect(removeItem).toHaveBeenCalledOnce(); + // 05-02. A discarded value must not read as "storage unavailable". + expect(record).toHaveBeenCalledWith({ + level: "warn", + eventId: "storage.operation.failed", + context: { + operation: "discard:COLOR_SCHEME", + error_kind: "STORAGE_UNAVAILABLE", + reason, + }, + }); expect(JSON.stringify(record.mock.calls)).not.toMatch( /private|malformed|unexpected/, ); @@ -549,6 +561,11 @@ describe("storage registry", () => { code: "CHUNK_RELOAD_GUARD_WRITE_SIZE_LIMIT_EXCEEDED", }, }); + expect(record).toHaveBeenCalledWith( + expect.objectContaining({ + context: expect.objectContaining({ reason: "SIZE_LIMIT_EXCEEDED" }), + }), + ); expect(setItem).not.toHaveBeenCalled(); expect(JSON.stringify({ result, calls: record.mock.calls })).not.toContain( secret,