Compare commits

...
Author SHA1 Message Date
Julius Marmingeandcodex 2b98359c8b [codex] structure legacy connection migration errors
Co-authored-by: codex <[email protected]>
2026-06-20 07:13:45 -07:00
2 changed files with 45 additions and 16 deletions

No files matched your search

@@ -75,4 +75,30 @@ describe("migrateLegacyConnectionCatalog", () => {
expect(catalog.targets).toEqual([]);
}),
);
it.effect("preserves the JSON parse failure", () =>
Effect.gen(function* () {
const error = yield* Effect.flip(migrateLegacyConnectionCatalog("{"));
expect(error).toMatchObject({
_tag: "LegacyConnectionDocumentParseError",
cause: expect.any(SyntaxError),
});
expect(error.message).toBe("Could not parse the legacy mobile connection catalog.");
}),
);
it.effect("preserves the schema decode failure", () =>
Effect.gen(function* () {
const error = yield* Effect.flip(
migrateLegacyConnectionCatalog(JSON.stringify({ connections: "invalid" })),
);
expect(error).toMatchObject({
_tag: "LegacyConnectionDocumentDecodeError",
cause: { _tag: "SchemaError" },
});
expect(error.message).toBe("Could not decode the legacy mobile connection catalog.");
}),
);
});
+19 -16
View File
@@ -33,12 +33,23 @@ const LegacyConnectionDocument = Schema.Struct({
});
const decodeLegacyConnectionDocument = Schema.decodeUnknownEffect(LegacyConnectionDocument);
export class LegacyConnectionMigrationError extends Schema.TaggedErrorClass<LegacyConnectionMigrationError>()(
"LegacyConnectionMigrationError",
{
message: Schema.String,
},
) {}
export class LegacyConnectionDocumentParseError extends Schema.TaggedErrorClass<LegacyConnectionDocumentParseError>()(
"LegacyConnectionDocumentParseError",
{ cause: Schema.Defect() },
) {
override get message(): string {
return "Could not parse the legacy mobile connection catalog.";
}
}
export class LegacyConnectionDocumentDecodeError extends Schema.TaggedErrorClass<LegacyConnectionDocumentDecodeError>()(
"LegacyConnectionDocumentDecodeError",
{ cause: Schema.Defect() },
) {
override get message(): string {
return "Could not decode the legacy mobile connection catalog.";
}
}
function isRelayManaged(connection: typeof LegacySavedRemoteConnection.Type): boolean {
return connection.relayManaged === true || connection.authenticationMethod === "dpop";
@@ -92,18 +103,10 @@ export const migrateLegacyConnectionCatalog = Effect.fn(
)(function* (raw: string) {
const parsed = yield* Effect.try({
try: () => JSON.parse(raw) as unknown,
catch: (cause) =>
new LegacyConnectionMigrationError({
message: `Could not parse the legacy mobile connection catalog: ${String(cause)}`,
}),
catch: (cause) => new LegacyConnectionDocumentParseError({ cause }),
});
const legacy = yield* decodeLegacyConnectionDocument(parsed).pipe(
Effect.mapError(
(cause) =>
new LegacyConnectionMigrationError({
message: `Could not decode the legacy mobile connection catalog: ${String(cause)}`,
}),
),
Effect.mapError((cause) => new LegacyConnectionDocumentDecodeError({ cause })),
);
return (legacy.connections ?? []).reduce(migrateConnection, EMPTY_CONNECTION_CATALOG_DOCUMENT);