|
6 | 6 | ConnectionTargetStore, |
7 | 7 | EMPTY_CONNECTION_CATALOG_DOCUMENT, |
8 | 8 | EnvironmentCacheStore, |
| 9 | + encodeShellSnapshotForCache, |
9 | 10 | putRemoteDpopTokenInCatalog, |
10 | 11 | registerConnectionInCatalog, |
11 | 12 | removeCatalogValue, |
@@ -91,7 +92,6 @@ const ConnectionCatalogDocumentJson = Schema.fromJsonString(ConnectionCatalogDoc |
91 | 92 | const decodeConnectionCatalogDocument = Schema.decodeUnknownEffect(ConnectionCatalogDocumentJson); |
92 | 93 | const encodeConnectionCatalogDocument = Schema.encodeEffect(ConnectionCatalogDocumentJson); |
93 | 94 | const decodeStoredShellSnapshot = Schema.decodeUnknownEffect(StoredShellSnapshotJson); |
94 | | -const encodeStoredShellSnapshot = Schema.encodeEffect(StoredShellSnapshotJson); |
95 | 95 | const decodeStoredThreadSnapshot = Schema.decodeUnknownEffect(StoredThreadSnapshotJson); |
96 | 96 | const encodeStoredThreadSnapshot = Schema.encodeEffect(StoredThreadSnapshotJson); |
97 | 97 | const decodeStoredServerConfig = Schema.decodeUnknownEffect(StoredServerConfigJson); |
@@ -188,7 +188,9 @@ function writeDatabaseValue( |
188 | 188 | ) { |
189 | 189 | return Effect.callback<void, ConnectionTransientError>((resume) => { |
190 | 190 | const transaction = database.transaction(storeName, "readwrite"); |
191 | | - transaction.addEventListener("error", () => { |
| 191 | + // Every failed write fires "abort". A failed commit, such as |
| 192 | + // QuotaExceededError, fires only "abort" and no "error". |
| 193 | + transaction.addEventListener("abort", () => { |
192 | 194 | resume( |
193 | 195 | Effect.fail(catalogError("write", transaction.error ?? "Unknown IndexedDB write error")), |
194 | 196 | ); |
@@ -606,11 +608,17 @@ export const connectionStorageLayer = Layer.effectContext( |
606 | 608 | ), |
607 | 609 | saveShell: (environmentId, snapshot) => |
608 | 610 | Effect.gen(function* () { |
609 | | - const encoded = yield* encodeStoredShellSnapshot({ |
610 | | - schemaVersion: SHELL_SNAPSHOT_CACHE_SCHEMA_VERSION, |
611 | | - environmentId, |
612 | | - snapshot, |
613 | | - }).pipe(Effect.mapError((cause) => persistenceError("save-shell", cause))); |
| 611 | + const encodedSnapshot = yield* encodeShellSnapshotForCache(snapshot); |
| 612 | + const encoded = yield* Effect.try({ |
| 613 | + try: () => |
| 614 | + // @effect-diagnostics-next-line preferSchemaOverJson:off - the snapshot is already encoded. |
| 615 | + JSON.stringify({ |
| 616 | + schemaVersion: SHELL_SNAPSHOT_CACHE_SCHEMA_VERSION, |
| 617 | + environmentId, |
| 618 | + snapshot: encodedSnapshot, |
| 619 | + } satisfies typeof StoredShellSnapshot.Encoded), |
| 620 | + catch: (cause) => persistenceError("save-shell", cause), |
| 621 | + }); |
614 | 622 | yield* writeDatabaseValue(database, SHELL_STORE_NAME, environmentId, encoded); |
615 | 623 | }).pipe( |
616 | 624 | Effect.mapError((cause) => |
|
0 commit comments