Skip to content

Commit 8250712

Browse files
committed
🤖 Check workdir exists before spawning in LocalRuntime
Root cause of 'spawn bash ENOENT' was that the working directory didn't exist when spawn() was called. Node.js throws ENOENT when you try to spawn with a non-existent cwd. Now we check if the workdir exists before spawning and throw a clear error message if it doesn't. This prevents confusing ENOENT errors.
1 parent 7def2f3 commit 8250712

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/runtime/LocalRuntime.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,19 @@ export class LocalRuntime implements Runtime {
3636
exec(command: string, options: ExecOptions): ExecStream {
3737
const startTime = performance.now();
3838

39+
// Determine working directory
40+
const cwd = options.cwd ?? this.workdir;
41+
42+
// Verify working directory exists before spawning
43+
// If it doesn't exist, spawn will fail with ENOENT which is confusing
44+
if (!fs.existsSync(cwd)) {
45+
throw new RuntimeErrorClass(
46+
`Working directory does not exist: ${cwd}`,
47+
"exec",
48+
new Error(`ENOENT: no such file or directory, stat '${cwd}'`)
49+
);
50+
}
51+
3952
// Find bash path (important for CI environments where PATH may not be set)
4053
const bashPath = findBashPath();
4154
const nicePath = findNicePath();
@@ -48,7 +61,7 @@ export class LocalRuntime implements Runtime {
4861
: ["-c", command];
4962

5063
const childProcess = spawn(spawnCommand, spawnArgs, {
51-
cwd: options.cwd ?? this.workdir,
64+
cwd,
5265
env: {
5366
...process.env,
5467
...(options.env ?? {}),

0 commit comments

Comments
 (0)