[codex] Preserve client connection preparation causes (#3267)
Co-authored-by: codex <[email protected]>
This commit is contained in:
1 parent
babf6f4c9a
commit
d407d90156
5 files changed
+42
-13
No files matched your search
@@ -100,7 +100,8 @@ const capabilitiesLayer = Layer.succeedContext(
|
||||
(error) =>
|
||||
new ConnectionTransientError({
|
||||
reason: "network",
|
||||
detail: error.message,
|
||||
detail: "Could not read the T3 Cloud session token.",
|
||||
cause: error,
|
||||
}),
|
||||
),
|
||||
);
|
||||
@@ -126,7 +127,8 @@ const capabilitiesLayer = Layer.succeedContext(
|
||||
catch: (cause) =>
|
||||
new ConnectionTransientError({
|
||||
reason: "remote-unavailable",
|
||||
detail: `Could not load the mobile device identity: ${String(cause)}`,
|
||||
detail: "Could not load the mobile device identity.",
|
||||
cause,
|
||||
}),
|
||||
}).pipe(Effect.map(Option.some)),
|
||||
}),
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { ConnectionTransientError } from "@t3tools/client-runtime/connection";
|
||||
import {
|
||||
AuthStandardClientScopes,
|
||||
EnvironmentId,
|
||||
@@ -18,7 +19,7 @@ const TARGET: DesktopSshEnvironmentTarget = {
|
||||
|
||||
function makeBridge(
|
||||
calls: string[],
|
||||
options?: { readonly failDescriptor?: boolean },
|
||||
options?: { readonly descriptorError?: Error },
|
||||
): DesktopBridge {
|
||||
return {
|
||||
ensureSshEnvironment: async (target: DesktopSshEnvironmentTarget) => {
|
||||
@@ -32,8 +33,8 @@ function makeBridge(
|
||||
},
|
||||
fetchSshEnvironmentDescriptor: async () => {
|
||||
calls.push("descriptor");
|
||||
if (options?.failDescriptor === true) {
|
||||
throw new Error("descriptor unavailable");
|
||||
if (options?.descriptorError !== undefined) {
|
||||
throw options.descriptorError;
|
||||
}
|
||||
return {
|
||||
environmentId: EnvironmentId.make("environment-ssh"),
|
||||
@@ -78,11 +79,27 @@ describe("desktop SSH pairing", () => {
|
||||
const calls: string[] = [];
|
||||
|
||||
yield* provisionDesktopSshEnvironment(
|
||||
makeBridge(calls, { failDescriptor: true }),
|
||||
makeBridge(calls, { descriptorError: new Error("descriptor unavailable") }),
|
||||
TARGET,
|
||||
).pipe(Effect.flip);
|
||||
|
||||
expect(calls).toEqual(["ensure", "descriptor"]);
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("preserves SSH preparation causes without exposing their message", () =>
|
||||
Effect.gen(function* () {
|
||||
const cause = new Error("descriptor response contained a private endpoint");
|
||||
|
||||
const error = yield* provisionDesktopSshEnvironment(
|
||||
makeBridge([], { descriptorError: cause }),
|
||||
TARGET,
|
||||
).pipe(Effect.flip);
|
||||
|
||||
expect(error).toBeInstanceOf(ConnectionTransientError);
|
||||
expect(error.message).toBe("Could not prepare the SSH environment.");
|
||||
expect(error.message).not.toContain(cause.message);
|
||||
expect(error.cause).toBe(cause);
|
||||
}),
|
||||
);
|
||||
});
|
||||
@@ -111,11 +111,13 @@ function sshPreparationError(cause: unknown) {
|
||||
return new ConnectionBlockedError({
|
||||
reason: "authentication",
|
||||
detail: message,
|
||||
cause,
|
||||
});
|
||||
}
|
||||
return new ConnectionTransientError({
|
||||
reason: "remote-unavailable",
|
||||
detail: `Could not prepare the SSH environment: ${message}`,
|
||||
detail: "Could not prepare the SSH environment.",
|
||||
cause,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -172,7 +174,8 @@ const capabilitiesLayer = Layer.effectContext(
|
||||
(error) =>
|
||||
new ConnectionTransientError({
|
||||
reason: "network",
|
||||
detail: error.message,
|
||||
detail: "Could not read the T3 Cloud session token.",
|
||||
cause: error,
|
||||
}),
|
||||
),
|
||||
);
|
||||
@@ -194,7 +197,8 @@ const capabilitiesLayer = Layer.effectContext(
|
||||
catch: (cause) =>
|
||||
new ConnectionTransientError({
|
||||
reason: "remote-unavailable",
|
||||
detail: `Could not load the desktop primary credential: ${String(cause)}`,
|
||||
detail: "Could not load the desktop primary credential.",
|
||||
cause,
|
||||
}),
|
||||
}).pipe(Effect.map(Option.fromNullishOr)),
|
||||
});
|
||||
@@ -250,7 +254,8 @@ const capabilitiesLayer = Layer.effectContext(
|
||||
catch: (cause) =>
|
||||
new ConnectionTransientError({
|
||||
reason: "remote-unavailable",
|
||||
detail: `Could not disconnect the SSH environment: ${String(cause)}`,
|
||||
detail: "Could not disconnect the SSH environment.",
|
||||
cause,
|
||||
}),
|
||||
});
|
||||
}),
|
||||
|
||||
@@ -155,7 +155,10 @@ describe("connection onboarding", () => {
|
||||
expect(error).toMatchObject({
|
||||
_tag: "ConnectionBlockedError",
|
||||
reason: "configuration",
|
||||
message: "Enter a backend URL.",
|
||||
message: "The pairing details are invalid.",
|
||||
cause: expect.objectContaining({
|
||||
message: "Enter a backend URL.",
|
||||
}),
|
||||
});
|
||||
expect(calls).toEqual([]);
|
||||
}),
|
||||
|
||||
@@ -77,7 +77,8 @@ const resolvePairingTarget = Effect.fn("clientRuntime.connection.onboarding.reso
|
||||
catch: (cause) =>
|
||||
new ConnectionBlockedError({
|
||||
reason: "configuration",
|
||||
detail: cause instanceof Error ? cause.message : "The pairing details are invalid.",
|
||||
detail: "The pairing details are invalid.",
|
||||
cause,
|
||||
}),
|
||||
});
|
||||
},
|
||||
@@ -189,7 +190,8 @@ export const prepareBearerConnectionUpdate = Effect.fn(
|
||||
catch: (cause) =>
|
||||
new ConnectionBlockedError({
|
||||
reason: "configuration",
|
||||
detail: cause instanceof Error ? cause.message : "The environment URL is invalid.",
|
||||
detail: "The environment URL is invalid.",
|
||||
cause,
|
||||
}),
|
||||
});
|
||||
const connectionId = entry.target.connectionId;
|
||||
|
||||
Reference in new issue
Block a user