Skip to content

Commit 889d347

Browse files
t3dotggclaude
andcommitted
fix(connect): name relay-side errors and missing local credentials correctly
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 02c8028 commit 889d347

4 files changed

Lines changed: 42 additions & 3 deletions

File tree

‎packages/client-runtime/src/connection/diagnosis.test.ts‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ import {
77
import { describe, expect, it } from "@effect/vitest";
88

99
import { connectionDiagnosisText, presentConnectionDiagnosis } from "./diagnosis.ts";
10-
import { mapManagedRelayError, mapRemoteEnvironmentError } from "./errors.ts";
10+
import {
11+
credentialMissingError,
12+
mapManagedRelayError,
13+
mapRemoteEnvironmentError,
14+
} from "./errors.ts";
1115
import {
1216
AVAILABLE_CONNECTION_STATE,
1317
type ConnectionAttemptError,
@@ -121,6 +125,24 @@ describe("presentConnectionDiagnosis", () => {
121125
]);
122126
});
123127

128+
it("does not blame this device's network when T3 Connect answered with an error", () => {
129+
const failure = mapManagedRelayError(
130+
new ManagedRelayRequestFailedError({
131+
action: "connect relay environment",
132+
cause: new Error("Bad Gateway"),
133+
status: 502,
134+
}),
135+
);
136+
const diagnosis = diagnose(backoff(failure));
137+
expect(diagnosis?.headline).toBe("T3 Connect returned an error");
138+
expect(diagnosis?.steps.join(" ")).not.toContain("this device");
139+
});
140+
141+
it("blames this device when its saved credential is missing", () => {
142+
const diagnosis = diagnose(backoff(credentialMissingError("connection-1")), "direct");
143+
expect(diagnosis?.hops[0]).toMatchObject({ hop: "device", result: "failed" });
144+
});
145+
124146
it("names clock skew from a DPoP time window rejection", () => {
125147
const failure = fromRelay(
126148
new RelayAuthInvalidError({

‎packages/client-runtime/src/connection/diagnosis.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ function headline(host: string, located: Located, failure: ConnectionAttemptErro
8484
return "This device's clock is off";
8585
case "not_linked":
8686
return `${host} is not linked to your T3 Connect account`;
87+
case "relay_error":
88+
return "T3 Connect returned an error";
8789
case "tunnel_pending":
8890
return `${host}'s tunnel is still being set up`;
8991
case "tunnel_not_enabled":
@@ -144,6 +146,11 @@ function steps(host: string, located: Located, failure: ConnectionAttemptError |
144146
];
145147
case "tunnel_pending":
146148
return ["Wait a minute. T3 Code retries on its own.", checkHost];
149+
case "relay_error":
150+
return [
151+
"Wait a few minutes. T3 Code retries on its own.",
152+
"If it keeps failing, copy the diagnostics and report it.",
153+
];
147154
case "tunnel_not_enabled":
148155
return [`On ${host}, open Settings > Connections and turn T3 Connect on.`];
149156
case "released":
@@ -168,7 +175,10 @@ function steps(host: string, located: Located, failure: ConnectionAttemptError |
168175
}
169176
switch (located.hop) {
170177
case "device":
171-
return ["Restart T3 Code on this device."];
178+
return [
179+
"Restart T3 Code on this device.",
180+
`If it keeps failing, remove ${host} from this device and add it again.`,
181+
];
172182
case "relay":
173183
return failure?.reason === "authentication"
174184
? ["Sign out of T3 Connect and sign in again."]

‎packages/client-runtime/src/connection/errors.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ export function profileMissingError(connectionId: string): ConnectionBlockedErro
1414
return new ConnectionBlockedError({
1515
reason: "configuration",
1616
detail: `Connection profile ${connectionId} is unavailable.`,
17+
hop: "device",
1718
});
1819
}
1920

2021
export function credentialMissingError(connectionId: string): ConnectionBlockedError {
2122
return new ConnectionBlockedError({
2223
reason: "authentication",
2324
detail: `Connection credential ${connectionId} is unavailable.`,
25+
hop: "device",
2426
});
2527
}
2628

@@ -126,6 +128,7 @@ function relayProtectedError(error: RelayProtectedError): ConnectionAttemptError
126128
detail,
127129
traceId,
128130
hop: "relay",
131+
failureCause: "relay_error",
129132
});
130133
}
131134
}
@@ -140,7 +143,10 @@ export function mapManagedRelayError(error: ManagedRelayClientError): Connection
140143
reason: "relay-unavailable",
141144
detail: error.message,
142145
hop: "relay",
143-
...(error.status !== undefined ? { httpStatus: error.status } : {}),
146+
// A status means the relay answered, so this device did reach it.
147+
...(error.status !== undefined
148+
? { httpStatus: error.status, failureCause: "relay_error" }
149+
: {}),
144150
...(error.traceId ? { traceId: error.traceId } : {}),
145151
});
146152
case "ManagedRelayRequestTimeoutError":

‎packages/client-runtime/src/connection/model.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ export const ConnectionFailureCause = Schema.Literals([
8686
...RelayEnvironmentEndpointFailure.literals,
8787
"clock_skew",
8888
"not_linked",
89+
"relay_error",
8990
"tunnel_pending",
9091
"tunnel_not_enabled",
9192
]);

0 commit comments

Comments
 (0)