From d407d901563015156ece53ef4d152c98f3bc36b8 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sat, 20 Jun 2026 12:59:41 -0700 Subject: [PATCH] [codex] Preserve client connection preparation causes (#3267) Co-authored-by: codex --- apps/mobile/src/connection/platform.ts | 6 +++-- apps/web/src/connection/platform.test.ts | 25 ++++++++++++++++--- apps/web/src/connection/platform.ts | 13 +++++++--- .../src/connection/onboarding.test.ts | 5 +++- .../src/connection/onboarding.ts | 6 +++-- 5 files changed, 42 insertions(+), 13 deletions(-) diff --git a/apps/mobile/src/connection/platform.ts b/apps/mobile/src/connection/platform.ts index 769632a8fc..0e33f2f0ec 100644 --- a/apps/mobile/src/connection/platform.ts +++ b/apps/mobile/src/connection/platform.ts @@ -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)), }), diff --git a/apps/web/src/connection/platform.test.ts b/apps/web/src/connection/platform.test.ts index 2b428e2669..3027105b31 100644 --- a/apps/web/src/connection/platform.test.ts +++ b/apps/web/src/connection/platform.test.ts @@ -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); + }), + ); }); diff --git a/apps/web/src/connection/platform.ts b/apps/web/src/connection/platform.ts index 1b7cba5cbf..45346f07e7 100644 --- a/apps/web/src/connection/platform.ts +++ b/apps/web/src/connection/platform.ts @@ -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, }), }); }), diff --git a/packages/client-runtime/src/connection/onboarding.test.ts b/packages/client-runtime/src/connection/onboarding.test.ts index 9bee0dad6f..2bdd57dbea 100644 --- a/packages/client-runtime/src/connection/onboarding.test.ts +++ b/packages/client-runtime/src/connection/onboarding.test.ts @@ -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([]); }), diff --git a/packages/client-runtime/src/connection/onboarding.ts b/packages/client-runtime/src/connection/onboarding.ts index e76bcd50a2..39db24a8a1 100644 --- a/packages/client-runtime/src/connection/onboarding.ts +++ b/packages/client-runtime/src/connection/onboarding.ts @@ -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;