Skip to content

Commit 3cba0b7

Browse files
saphidclaude
andcommitted
fix(web): device host checks show the error without a stack trace
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 61c3794 commit 3cba0b7

2 files changed

Lines changed: 66 additions & 2 deletions

File tree

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { DeviceHostUnavailableError, EnvironmentId } from "@t3tools/contracts";
2+
import * as Cause from "effect/Cause";
3+
import { AsyncResult } from "effect/reactivity";
4+
import { describe, expect, it, vi } from "vite-plus/test";
5+
6+
import { act, render } from "../../../test/render";
7+
8+
const state = vi.hoisted(() => ({ test: vi.fn() }));
9+
function setup() {
10+
state.test.mockReset();
11+
}
12+
13+
vi.mock(import("../../state/use-atom-command"), async (original) => ({
14+
...(await original()),
15+
useAtomCommand: (() => state.test) as never,
16+
}));
17+
vi.mock(import("../../state/session"), async (original) => ({
18+
...(await original()),
19+
readEnvironmentScope: (() => true) as never,
20+
}));
21+
22+
import { useHostConnectionChecks } from "./useHostConnectionChecks";
23+
24+
const environmentId = EnvironmentId.make("environment-1");
25+
const targets = [{ environmentId, label: "This Mac", connected: true }];
26+
27+
function Harness({
28+
onReady,
29+
}: {
30+
onReady: (run: ReturnType<typeof useHostConnectionChecks>) => void;
31+
}) {
32+
onReady(useHostConnectionChecks(targets));
33+
return null;
34+
}
35+
36+
describe("useHostConnectionChecks", () => {
37+
it("reports a failed check by its message, without a stack trace", async () => {
38+
setup();
39+
state.test.mockResolvedValue(
40+
AsyncResult.failure(
41+
Cause.fail(
42+
new DeviceHostUnavailableError({
43+
hostId: "mac",
44+
hostLabel: "Mac mini",
45+
reason: "SSH connection refused.",
46+
}),
47+
),
48+
),
49+
);
50+
let checks!: ReturnType<typeof useHostConnectionChecks>;
51+
await using _screen = await render(<Harness onReady={(next) => (checks = next)} />, {
52+
router: false, // the hook reads no route state
53+
});
54+
55+
const results = await act(() =>
56+
checks.testConnection({ kind: "ssh", id: "mac", label: "Mac mini", target: "user@mac" }),
57+
);
58+
59+
expect(results?.[environmentId]).toEqual({
60+
status: "failed",
61+
error: "Mac mini is unavailable: SSH connection refused.",
62+
});
63+
});
64+
});

‎apps/web/src/components/settings/useHostConnectionChecks.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { AuthSettingsWriteScope } from "@t3tools/contracts";
22
import { readEnvironmentScope } from "../../state/session";
33
import { useRef, useState } from "react";
4-
import * as Cause from "effect/Cause";
4+
import { squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime";
55
import type { SshDeviceHostConfig } from "@t3tools/contracts";
66
import { deviceEnvironment } from "../../state/device";
77
import { useAtomCommand } from "../../state/use-atom-command";
@@ -30,7 +30,7 @@ export function useHostConnectionChecks(targets: ReadonlyArray<DeviceHostCheckTa
3030
throw new Error("This connection cannot test device hosts.");
3131
}
3232
const result = await test({ environmentId, input });
33-
if (result._tag === "Failure") throw new Error(Cause.pretty(result.cause));
33+
if (result._tag === "Failure") throw squashAtomCommandFailure(result);
3434
return result.value;
3535
},
3636
(environmentId, result) => {

0 commit comments

Comments
 (0)