Skip to content

Commit 18520a8

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 7c4e3f3 commit 18520a8

1 file changed

Lines changed: 15 additions & 16 deletions

File tree

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

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import {
2727
readChromiumCookies,
2828
type CookieReadResult,
2929
} from "./ChromiumCookies.ts";
30-
import type { ImportedCookie } from "./CookieDatabase.ts";
3130
import { FirefoxCookieReadError, readFirefoxCookies } from "./FirefoxCookies.ts";
3231
import {
3332
BROWSER_IMPORT_SOURCES,
@@ -164,11 +163,9 @@ export const make = Effect.gen(function* BrowserImportMake() {
164163
});
165164
}
166165

167-
// Both branches fail with a tagged error carrying a `reason`, so the union
168-
// stays structurally identifiable rather than collapsing to an anonymous
169-
// shape that `Effect.catchTags` could not tell apart.
170166
// Both branches fail with a tagged error, so the union stays structurally
171-
// identifiable. The success side is normalized to one shape too, so the
167+
// identifiable and each tag is handled on its own below. The success side
168+
// is normalized to one shape too, so the
172169
// skipped tally survives either engine — Firefox stores plaintext, so
173170
// nothing there is ever unreadable.
174171
const read: Effect.Effect<
@@ -192,17 +189,19 @@ export const make = Effect.gen(function* BrowserImportMake() {
192189
const result = yield* read.pipe(
193190
Effect.scoped,
194191
Effect.provide(platformServices),
195-
Effect.mapError(
196-
(cause) =>
197-
new BrowserImportFailedError({
198-
sourceId: definition.id,
199-
// Firefox has one failure mode — its plaintext database would not
200-
// open — so its error carries no reason of its own and the
201-
// user-facing one is supplied here.
202-
reason: cause._tag === "FirefoxCookieReadError" ? "readFailed" : cause.reason,
203-
cause,
204-
}),
205-
),
192+
Effect.catchTags({
193+
ChromiumCookieReadError: (cause) =>
194+
Effect.fail(
195+
new BrowserImportFailedError({ sourceId: definition.id, reason: cause.reason, cause }),
196+
),
197+
// Firefox has one failure mode — its plaintext database would not open
198+
// — so its error carries no reason of its own and the user-facing one
199+
// is supplied here.
200+
FirefoxCookieReadError: (cause) =>
201+
Effect.fail(
202+
new BrowserImportFailedError({ sourceId: definition.id, reason: "readFailed", cause }),
203+
),
204+
}),
206205
);
207206

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

0 commit comments

Comments
 (0)