Skip to content

Commit 01eec28

Browse files
authored
fix(cli): render gateway transport failures as expected conditions (#125556)
* fix(cli): render gateway transport failures as expected conditions An unreachable gateway is an expected, recoverable operator condition, but only the devices command family surfaced it through the root failure handler, where it rendered as "The CLI command failed" with debug hints. Extract GatewayTransportError into its own module so the failure renderer can classify it without importing the transport stack, and treat it as an expected CLI error alongside missing credentials. * fix(gateway): import the transport error kind used by the JSON shape * test(cli): extract the process-test gateway harness The new devices coverage pushed gateway-backed-exit.process.test.ts past the max-lines budget, and that file is not in the ratchet baseline. Move the mock Gateway servers into a sibling test-helpers module instead of suppressing the rule.
1 parent 7e7b860 commit 01eec28

7 files changed

Lines changed: 422 additions & 274 deletions

‎config/assertion-safety-baseline.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2901,7 +2901,7 @@ src/gateway/agent-turn/internal-facade.ts 4
29012901
src/gateway/board-host-tools.ts 1
29022902
src/gateway/board-view-ticket.ts 1
29032903
src/gateway/boot.ts 1
2904-
src/gateway/call.ts 7
2904+
src/gateway/call.ts 6
29052905
src/gateway/channel-health-monitor.ts 6
29062906
src/gateway/channel-thaw-restart.ts 1
29072907
src/gateway/chat-attachments.ts 4

‎src/cli/failure-output.test.ts‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Failure output tests cover CLI error formatting and failure summaries.
22
import { describe, expect, it } from "vitest";
3-
import { GatewayCredentialsRequiredError } from "../gateway/call.js";
3+
import { GatewayCredentialsRequiredError, GatewayTransportError } from "../gateway/call.js";
44
import {
55
ExpectedCliError,
66
formatCliFailureLines,
@@ -157,6 +157,20 @@ describe("formatCliFailureLines", () => {
157157
configPath: "/tmp/openclaw.json",
158158
}),
159159
},
160+
{
161+
label: "unreachable gateway",
162+
createError: () =>
163+
new GatewayTransportError({
164+
kind: "closed",
165+
message:
166+
"Gateway not reachable at ws://127.0.0.1:51078 (ECONNREFUSED).\nStart it with `openclaw gateway run` or check `openclaw gateway status`.",
167+
connectionDetails: {
168+
url: "ws://127.0.0.1:51078",
169+
urlSource: "local loopback",
170+
message: "Gateway target: ws://127.0.0.1:51078",
171+
},
172+
}),
173+
},
160174
])(
161175
"routes $label through the shared expected-condition predicate without crash framing",
162176
({ createError }) => {

‎src/cli/failure-output.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Shared root CLI failure formatting with debug stack gating and recovery hints.
2+
import { isGatewayTransportError } from "../gateway/transport-error.js";
23
import { isTruthyEnvValue } from "../infra/env.js";
34
import { formatErrorMessage, formatUncaughtError } from "../infra/errors.js";
45
import { formatCliCommand } from "./command-format.js";
@@ -58,7 +59,11 @@ function isGatewayCredentialsCliError(
5859
}
5960

6061
export function isExpectedCliError(error: unknown): error is Error {
61-
return error instanceof ExpectedCliError || isGatewayCredentialsCliError(error);
62+
return (
63+
error instanceof ExpectedCliError ||
64+
isGatewayCredentialsCliError(error) ||
65+
isGatewayTransportError(error)
66+
);
6267
}
6368

6469
export function rethrowExpectedCliError(error: unknown): void {

0 commit comments

Comments
 (0)