The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 23, 04:15 UTC
fix(server): report spawn ENOTDIR as a spawn error instead of a defect (#14345)
Gabriel Rojas committed
Oct 18, 2026 at 16:12 UTC
bafadf324c9f3d8a59083d88a6e1e0c630d5182c
2 files changed
+44
-13
apps/server/src/processRunner.test.ts
+27
@@ -202,6 +202,33 @@ describe("runProcess", () => {
202
}),
203
);
204
205
+ it.effect("types spawn failures that the platform spawner throws synchronously", () =>
206
+ Effect.gen(function* () {
207
+ // A non-directory entry on PATH makes node's spawn throw ENOTDIR
208
+ // synchronously. The platform spawner calls it inside `Effect.callback`,
209
+ // so the throw arrives as a defect rather than a typed error.
210
+ const defect = Object.assign(new Error("spawn jj ENOTDIR"), { code: "ENOTDIR" });
211
+ const spawner = makeSpawner(() =>
212
+ Effect.callback<never, never>(() => {
213
+ throw defect;
214
+ }),
215
+ );
216
+
217
+ const error = yield* runWith(spawner)({
218
+ command: "jj",
219
+ args: ["--version"],
220
+ cwd: "/repo",
221
+ }).pipe(Effect.flip);
222
+
223
+ expect(error._tag).toBe("ProcessSpawnError");
224
+ if (error._tag !== "ProcessSpawnError") {
225
+ return expect.fail("Expected ProcessSpawnError");
226
+ }
227
+ expect(error).toMatchObject({ command: "jj", argumentCount: 1, cwd: "/repo" });
228
+ expect(error.cause).toBe(defect);
229
+ }),
230
+ );
231
+
232
it.effect("fails when output exceeds max buffer in default mode", () =>
233
Effect.gen(function* () {
234
const spawner = makeSpawner(() => Effect.succeed(makeHandle({ stdout: "x".repeat(2048) })));
apps/server/src/processRunner.ts
+17
-13
@@ -281,6 +281,18 @@ const runProcessCore = Effect.fn("processRunner.runProcessCore")(function* (
281
input.env === undefined ? {} : { env: input.env, extendEnv },
282
);
283
284
+ const toSpawnError = (cause: unknown) =>
285
+ new ProcessSpawnError({
286
+ command: input.command,
287
+ argumentCount: input.args.length,
288
+ cwd: input.cwd,
289
+ spawnCwd: input.spawnCwd,
290
+ resolvedCommand: spawnCommand.command,
291
+ resolvedArgumentCount: spawnCommand.args.length,
292
+ shell: spawnCommand.shell,
293
+ cause,
294
+ });
295
+
296
const child = yield* spawner
297
.spawn(
298
ChildProcess.make(spawnCommand.command, spawnCommand.args, {
@@ -295,19 +307,11 @@ const runProcessCore = Effect.fn("processRunner.runProcessCore")(function* (
307
}),
308
)
309
.pipe(
298
- Effect.mapError(
299
- (cause) =>
300
- new ProcessSpawnError({
301
- command: input.command,
302
- argumentCount: input.args.length,
303
- cwd: input.cwd,
304
- spawnCwd: input.spawnCwd,
305
- resolvedCommand: spawnCommand.command,
306
- resolvedArgumentCount: spawnCommand.args.length,
307
- shell: spawnCommand.shell,
308
- cause,
309
- }),
310
- ),
310
+ Effect.mapError(toSpawnError),
311
+ // Node's spawn can also throw synchronously, e.g. ENOTDIR when a PATH
312
+ // entry is a file. That arrives as a defect, which `mapError` never sees,
313
+ // so callers that recover from spawn failures would be bypassed.
314
+ Effect.catchDefect((cause) => Effect.fail(toSpawnError(cause))),
315
);
316
317
const stdin = input.stdin;