Skip to content

Commit d711865

Browse files
author
Julius Marminge
committed
Handle missing host-label commands safely
1 parent a5bf3b5 commit d711865

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

‎apps/server/src/environment/Layers/ServerEnvironmentLabel.test.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,20 @@ describe("resolveServerEnvironmentLabel", () => {
114114
}),
115115
);
116116

117+
it.effect("falls back to the hostname when the friendly-label command is missing", () =>
118+
Effect.gen(function* () {
119+
mockedRunProcess.mockRejectedValueOnce(new Error("spawn scutil ENOENT"));
120+
121+
const result = yield* resolveServerEnvironmentLabel({
122+
cwdBaseName: "t3code",
123+
platform: "darwin",
124+
hostname: "macbook-pro",
125+
}).pipe(Effect.provide(NoopFileSystemLayer));
126+
127+
expect(result).toBe("macbook-pro");
128+
}),
129+
);
130+
117131
it.effect("falls back to the cwd basename when the hostname is blank", () =>
118132
Effect.gen(function* () {
119133
mockedRunProcess.mockResolvedValueOnce({

‎apps/server/src/environment/Layers/ServerEnvironmentLabel.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const runFriendlyLabelCommand = Effect.fn("runFriendlyLabelCommand")(function* (
5151
command: string,
5252
args: readonly string[],
5353
) {
54-
const result = yield* Effect.promise(() =>
54+
const result = yield* Effect.tryPromise(() =>
5555
runProcess(command, args, {
5656
allowNonZeroExit: true,
5757
}),

0 commit comments

Comments
 (0)