Skip to content

Commit 39a698d

Browse files
committed
fix(server): handle HostProcessWorkingDirectory cwd defects via Exit
Effect.catch cannot run on the Reference (error type never) and also misses defects when process.cwd() throws. Use Effect.exit so a deleted cwd falls through to home/tmpdir instead of failing the probe.
1 parent ceb4e35 commit 39a698d

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

‎apps/server/src/provider/providerProbeTimeouts.ts‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as NodeFs from "node:fs";
22
import * as NodeOs from "node:os";
33
import * as Effect from "effect/Effect";
4+
import * as Exit from "effect/Exit";
45
import {
56
HostProcessEnvironment,
67
HostProcessWorkingDirectory,
@@ -133,9 +134,14 @@ export const resolveProviderProbeCwd = Effect.fn("resolveProviderProbeCwd")(func
133134
environment?: NodeJS.ProcessEnv,
134135
) {
135136
const env = environment ?? (yield* HostProcessEnvironment);
136-
const workingDirectory = yield* HostProcessWorkingDirectory.pipe(
137-
Effect.map((cwd) => (cwd.trim().length > 0 ? cwd : undefined)),
138-
Effect.catch(() => Effect.succeed(undefined as string | undefined)),
137+
// HostProcessWorkingDirectory is typed as infallible, but its defaultValue
138+
// calls process.cwd() which can throw a defect when cwd is gone. Use Exit so
139+
// defects fall through to home/tmpdir instead of failing the probe.
140+
const workingDirectoryExit = yield* Effect.exit(
141+
Effect.map(HostProcessWorkingDirectory, (cwd) => (cwd.trim().length > 0 ? cwd : undefined)),
139142
);
143+
const workingDirectory = Exit.isSuccess(workingDirectoryExit)
144+
? workingDirectoryExit.value
145+
: undefined;
140146
return resolveProviderProbeCwdSync(preferred, env, workingDirectory);
141147
});

0 commit comments

Comments
 (0)