Skip to content

Commit 43dca40

Browse files
StiensWoutcodex
andcommitted
Address remote protocol error diagnostics
Co-authored-by: Codex <codex@openai.com>
1 parent c1ecfb1 commit 43dca40

2 files changed

Lines changed: 14 additions & 12 deletions

File tree

packages/shared/src/remote.test.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ describe("remote", () => {
8383
}
8484

8585
expect(pairingUrlError).toBeInstanceOf(RemotePairingUrlInvalidError);
86-
expect((pairingUrlError as RemotePairingUrlInvalidError).cause).toBeInstanceOf(Error);
86+
expect(pairingUrlError).toMatchObject({ protocol: "ftp:" });
87+
expect((pairingUrlError as RemotePairingUrlInvalidError).cause).toBeUndefined();
8788
});
8889

8990
it("rejects unsupported hosted pairing backend protocols", () => {
@@ -98,8 +99,8 @@ describe("remote", () => {
9899
}
99100

100101
expect(hostError).toBeInstanceOf(RemoteBackendUrlInvalidError);
101-
expect(hostError).toMatchObject({ source: "hosted-pairing-host" });
102-
expect((hostError as RemoteBackendUrlInvalidError).cause).toBeInstanceOf(Error);
102+
expect(hostError).toMatchObject({ source: "hosted-pairing-host", protocol: "ftp:" });
103+
expect((hostError as RemoteBackendUrlInvalidError).cause).toBeUndefined();
103104
});
104105

105106
it("rejects unsupported direct host protocols", () => {
@@ -114,8 +115,8 @@ describe("remote", () => {
114115
}
115116

116117
expect(hostError).toBeInstanceOf(RemoteBackendUrlInvalidError);
117-
expect(hostError).toMatchObject({ source: "direct-host" });
118-
expect((hostError as RemoteBackendUrlInvalidError).cause).toBeInstanceOf(Error);
118+
expect(hostError).toMatchObject({ source: "direct-host", protocol: "ftp:" });
119+
expect((hostError as RemoteBackendUrlInvalidError).cause).toBeUndefined();
119120
});
120121

121122
it("uses distinct structural errors for missing pairing inputs", () => {

packages/shared/src/remote.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ export class RemoteBackendUrlMissingError extends Schema.TaggedErrorClass<Remote
1919

2020
export class RemotePairingUrlInvalidError extends Schema.TaggedErrorClass<RemotePairingUrlInvalidError>()(
2121
"RemotePairingUrlInvalidError",
22-
{ cause: Schema.Defect() },
22+
{
23+
cause: Schema.optional(Schema.Defect()),
24+
protocol: Schema.optional(Schema.String),
25+
},
2326
) {
2427
override get message(): string {
2528
return "Pairing URL is invalid.";
@@ -30,7 +33,8 @@ export class RemoteBackendUrlInvalidError extends Schema.TaggedErrorClass<Remote
3033
"RemoteBackendUrlInvalidError",
3134
{
3235
source: Schema.Literals(["direct-host", "hosted-pairing-host"]),
33-
cause: Schema.Defect(),
36+
cause: Schema.optional(Schema.Defect()),
37+
protocol: Schema.optional(Schema.String),
3438
},
3539
) {
3640
override get message(): string {
@@ -65,9 +69,6 @@ export const RemotePairingTargetError = Schema.Union([
6569
]);
6670
export type RemotePairingTargetError = typeof RemotePairingTargetError.Type;
6771

68-
const createUnsupportedRemoteBackendProtocolError = (url: URL): TypeError =>
69-
new TypeError(`Unsupported remote backend URL protocol: ${url.protocol}`);
70-
7172
const hasSupportedRemoteBackendProtocol = (url: URL): boolean =>
7273
SUPPORTED_REMOTE_BACKEND_PROTOCOLS.has(url.protocol);
7374

@@ -93,7 +94,7 @@ const normalizeRemoteBaseUrl = (
9394
if (!hasSupportedRemoteBackendProtocol(url)) {
9495
throw new RemoteBackendUrlInvalidError({
9596
source,
96-
cause: createUnsupportedRemoteBackendProtocolError(url),
97+
protocol: url.protocol,
9798
});
9899
}
99100
url.pathname = "/";
@@ -199,7 +200,7 @@ export const resolveRemotePairingTarget = (input: {
199200
}
200201
if (!hasSupportedRemoteBackendProtocol(url)) {
201202
throw new RemotePairingUrlInvalidError({
202-
cause: createUnsupportedRemoteBackendProtocolError(url),
203+
protocol: url.protocol,
203204
});
204205
}
205206
const hostedPairingRequest = readHostedPairingRequest(url);

0 commit comments

Comments
 (0)