Skip to content

Commit 8538b6c

Browse files
refactor(desktop): handle the cookie read failures by tag
The union was discriminated with a `cause._tag` ternary inside `Effect.mapError` even though both members are statically known tagged errors; `Effect.catchTags` says the same thing without the manual check. The comment above `read` claiming both carry a `reason` was stale — Firefox's no longer does. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent a0365e9 commit 8538b6c

1 file changed

Lines changed: 16 additions & 14 deletions

File tree

apps/desktop/src/preview/BrowserImport/BrowserImport.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,9 @@ export const make = Effect.gen(function* BrowserImportMake() {
160160
});
161161
}
162162

163-
// Both branches fail with a tagged error carrying a `reason`, so the union
164-
// stays structurally identifiable rather than collapsing to an anonymous
165-
// shape that `Effect.catchTags` could not tell apart.
163+
// Both branches fail with a tagged error, so the union stays structurally
164+
// identifiable and each tag is handled on its own below rather than
165+
// collapsing to an anonymous shape.
166166
const read: Effect.Effect<
167167
ReadonlyArray<ImportedCookie>,
168168
ChromiumCookieReadError | FirefoxCookieReadError,
@@ -181,17 +181,19 @@ export const make = Effect.gen(function* BrowserImportMake() {
181181
const cookies = yield* read.pipe(
182182
Effect.scoped,
183183
Effect.provide(platformServices),
184-
Effect.mapError(
185-
(cause) =>
186-
new BrowserImportFailedError({
187-
sourceId: definition.id,
188-
// Firefox has one failure mode — its plaintext database would not
189-
// open — so its error carries no reason of its own and the
190-
// user-facing one is supplied here.
191-
reason: cause._tag === "FirefoxCookieReadError" ? "readFailed" : cause.reason,
192-
cause,
193-
}),
194-
),
184+
Effect.catchTags({
185+
ChromiumCookieReadError: (cause) =>
186+
Effect.fail(
187+
new BrowserImportFailedError({ sourceId: definition.id, reason: cause.reason, cause }),
188+
),
189+
// Firefox has one failure mode — its plaintext database would not open
190+
// — so its error carries no reason of its own and the user-facing one
191+
// is supplied here.
192+
FirefoxCookieReadError: (cause) =>
193+
Effect.fail(
194+
new BrowserImportFailedError({ sourceId: definition.id, reason: "readFailed", cause }),
195+
),
196+
}),
195197
);
196198

197199
const session = yield* browserSession.getSession(input.scope, input.persistent).pipe(

0 commit comments

Comments
 (0)