Skip to content

Commit 4306e77

Browse files
Jacksondr5claude
andauthored
fix(server): device list warnings keep the hub's error detail (#25248)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 41b3b0b commit 4306e77

2 files changed

Lines changed: 72 additions & 7 deletions

File tree

‎apps/server/src/device/DeviceHubOperations.ts‎

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,21 @@ const HubActionResult = Schema.Struct({
3939
),
4040
});
4141

42+
// Hub diagnostics can carry a whole stderr dump.
43+
const boundDiagnostics = (text: string) =>
44+
text.length > 2_000 ? `${text.slice(0, 1_999)}…` : text;
45+
46+
// The hub's `error` is a util.inspect of Node's exec error; the stack and the
47+
// inspected fields follow the first frame, so keep the lines before it.
48+
const errorHead = (error: string) => {
49+
const lines = error.split(/\r?\n/);
50+
const firstFrame = lines.findIndex((line) => /^\s+at /.test(line));
51+
return (firstFrame === -1 ? lines : lines.slice(0, firstFrame))
52+
.map((line) => line.trim())
53+
.filter(Boolean)
54+
.join(" ");
55+
};
56+
4257
const vendorPrefix = (platform: DevicePlatform) =>
4358
platform === "ios" ? "/vendor/serve-sim" : "/vendor/serve-emu";
4459

@@ -109,7 +124,11 @@ export const makeDeviceHubOperations = (options: {
109124
/(?:^Error:\s*ENOENT:|\bcode:\s*['"]ENOENT['"])/.test(error.error ?? "")
110125
),
111126
);
112-
const details = warnings?.map((error) => error.message) ?? [];
127+
const details =
128+
warnings?.map((error) => {
129+
const head = errorHead(error.error ?? "");
130+
return boundDiagnostics(head ? `${error.message} ${head}` : error.message);
131+
}) ?? [];
113132
let androidDiscoveryIncomplete = false;
114133
if (androidAvailable) {
115134
const avds = yield* run("emulator", ["-list-avds"]);
@@ -167,12 +186,7 @@ export const makeDeviceHubOperations = (options: {
167186
: /timed? out|timeout/i.test(diagnostics)
168187
? "timeout"
169188
: "launch_failed",
170-
...(diagnostics
171-
? {
172-
diagnostics:
173-
diagnostics.length > 2_000 ? `${diagnostics.slice(0, 1_999)}…` : diagnostics,
174-
}
175-
: {}),
189+
...(diagnostics ? { diagnostics: boundDiagnostics(diagnostics) } : {}),
176190
cause: result,
177191
});
178192
}

‎apps/server/src/device/DeviceService.test.ts‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,57 @@ it.effect("hides Android discovery failures when the host has no Android SDK", (
638638
}).pipe(Effect.scoped),
639639
);
640640

641+
// The hub reports `error` as a util.inspect of Node's exec error.
642+
const simctlMessage = "[apple-utils] Failed to run `xcrun simctl list devices --json`:";
643+
const simctlCause =
644+
"An error was encountered processing the command (domain=NSPOSIXErrorDomain, code=60): Unable to connect to CoreSimulatorService [xcrun shim fail mode]";
645+
const simctlError = `Error: Command failed: xcrun simctl list devices --json
646+
${simctlCause}
647+
648+
at genericNodeError (node:internal/errors:986:15)
649+
at wrappedFn (node:internal/errors:540:14)
650+
at ChildProcess.exithandler (node:child_process:417:12)
651+
at ChildProcess._handle.onexit (node:internal/child_process:335:5) {
652+
code: 1,
653+
killed: false,
654+
signal: null,
655+
cmd: 'xcrun simctl list devices --json',
656+
stdout: '',
657+
stderr: '${simctlCause}\\n'
658+
}`;
659+
const avdmanager = "/Users/test/Library/Android/sdk/cmdline-tools/latest/bin/avdmanager";
660+
const avdmanagerError = `Error: spawn ${avdmanager} ENOENT
661+
at ChildProcess._handle.onexit (node:internal/child_process:316:19)
662+
at onErrorNT (node:internal/child_process:524:16) {
663+
errno: -2,
664+
code: 'ENOENT',
665+
syscall: 'spawn ${avdmanager}',
666+
path: '${avdmanager}',
667+
spawnargs: [ 'list', 'avd' ],
668+
cmd: '${avdmanager} list avd',
669+
stdout: '',
670+
stderr: ''
671+
}`;
672+
673+
it.effect("keeps the cause from the hub's error in discovery warnings, without the stack", () =>
674+
Effect.gen(function* () {
675+
const { service, discoveryErrors } = yield* fixture();
676+
yield* Ref.set(discoveryErrors, [
677+
{ message: simctlMessage, error: simctlError },
678+
{ message: "[android-utils] Failed to run `avdmanager list avd`:", error: avdmanagerError },
679+
]);
680+
const state = yield* service.configure({ enabled: true });
681+
expect(state.hostStatusDetail).toBe(
682+
[
683+
`${simctlMessage} Error: Command failed: xcrun simctl list devices --json ${simctlCause}`,
684+
`[android-utils] Failed to run \`avdmanager list avd\`: Error: spawn ${avdmanager} ENOENT`,
685+
].join("\n"),
686+
);
687+
expect(state.hostStatusDetail).not.toContain(" at ");
688+
expect(state.hostStatusDetail).not.toContain("stderr:");
689+
}).pipe(Effect.scoped),
690+
);
691+
641692
it.effect.each([
642693
{
643694
diagnostic: "Insufficient disk space at /private/user/path",

0 commit comments

Comments
 (0)