Skip to content

Commit 7c4e3f3

Browse files
refactor(desktop): drop the redundant reason from the Firefox read error
Firefox has one failure mode — its plaintext database would not open — so a single-value `reason` literal encoded the same thing as the tag, and `cause` was optional though every construction site wraps a real failure. The error now carries the database path and a required cause, and `BrowserImport` supplies the user-facing reason where it maps the union. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent fd76cc0 commit 7c4e3f3

2 files changed

Lines changed: 17 additions & 14 deletions

File tree

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,14 @@ export const make = Effect.gen(function* BrowserImportMake() {
194194
Effect.provide(platformServices),
195195
Effect.mapError(
196196
(cause) =>
197-
new BrowserImportFailedError({ sourceId: definition.id, reason: cause.reason, 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+
}),
198205
),
199206
);
200207

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

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,30 +22,30 @@ import { cookieScope, snapshotCookieDatabase, type ImportedCookie } from "./Cook
2222
* that is the modern default, and guessing "none" would widen a cookie's scope
2323
* on import.
2424
*/
25-
export const FirefoxCookieReadReason = Schema.Literals(["readFailed"]);
26-
export type FirefoxCookieReadReason = typeof FirefoxCookieReadReason.Type;
27-
2825
/**
2926
* Mirrors `ChromiumCookieReadError` so both engines fail with a tagged error
3027
* the service can tell apart, rather than one of them widening the channel to
3128
* an anonymous shape.
29+
*
30+
* No `reason` field: unlike Chromium there is only one way this fails — the
31+
* plaintext database would not open — and the tag already says which engine it
32+
* was. `BrowserImport` supplies the user-facing reason when it maps the union.
3233
*/
3334
export class FirefoxCookieReadError extends Schema.TaggedErrorClass<FirefoxCookieReadError>()(
3435
"FirefoxCookieReadError",
3536
{
36-
reason: FirefoxCookieReadReason,
3737
/**
3838
* Which database the read was for. Firefox keeps one per profile, so
3939
* without it a failure cannot be traced back to the profile that caused
4040
* it.
4141
*/
4242
cookieDatabasePath: Schema.String,
43-
/** Kept for the log; never surfaced to the user. */
44-
cause: Schema.optional(Schema.Defect()),
43+
/** Always present: every construction site wraps a real failure. */
44+
cause: Schema.Defect(),
4545
},
4646
) {
4747
override get message(): string {
48-
return `Could not read Firefox cookies at ${this.cookieDatabasePath}: ${this.reason}.`;
48+
return `Could not read Firefox cookies at ${this.cookieDatabasePath}.`;
4949
}
5050
}
5151

@@ -73,9 +73,7 @@ export const readFirefoxCookies = Effect.fn("FirefoxCookies.readFirefoxCookies")
7373
cookieDatabasePath: string,
7474
) {
7575
const snapshotPath = yield* snapshotCookieDatabase(cookieDatabasePath).pipe(
76-
Effect.mapError(
77-
(cause) => new FirefoxCookieReadError({ reason: "readFailed", cookieDatabasePath, cause }),
78-
),
76+
Effect.mapError((cause) => new FirefoxCookieReadError({ cookieDatabasePath, cause })),
7977
);
8078

8179
const rows = yield* Effect.gen(function* () {
@@ -93,9 +91,7 @@ export const readFirefoxCookies = Effect.fn("FirefoxCookies.readFirefoxCookies")
9391
return yield* decodeCookieRows(raw);
9492
}).pipe(
9593
Effect.provide(NodeSqliteClient.layer({ filename: snapshotPath, readonly: true })),
96-
Effect.mapError(
97-
(cause) => new FirefoxCookieReadError({ reason: "readFailed", cookieDatabasePath, cause }),
98-
),
94+
Effect.mapError((cause) => new FirefoxCookieReadError({ cookieDatabasePath, cause })),
9995
);
10096

10197
return rows.map((row) => {

0 commit comments

Comments
 (0)