{"record":{"id":"583a222903b3b2f8","repo":"denoland/deno","slug":"failed-to-spawn-no-such-cwd","errorCode":null,"errorMessage":"Failed to spawn '{}': No such cwd '{}'","messagePattern":"Failed to spawn '(.+?)': No such cwd '(.+?)'","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ext/process/lib.rs","lineNumber":1120,"sourceCode":"  // `ChildResource` implements its own `Drop` that kills the child process\n  // by PID when `kill_on_drop` is true. This allows `unref()` to disable\n  // kill-on-drop, so the child can outlive the parent (matching Node.js\n  // semantics for `child_process.unref()`).\n\n  let child = match command.spawn() {\n    Ok(child) => child,\n    Err(err) => {\n      #[cfg(not(windows))]\n      let command = command.as_std();\n      let command_name = command.get_program().to_string_lossy();\n\n      if let Some(cwd) = command.get_current_dir() {\n        // launching a sub process always depends on the real\n        // file system so using these methods directly is ok\n        #[allow(clippy::disallowed_methods, reason = \"requires real fs\")]\n        if !cwd.exists() {\n          return Err(\n            std::io::Error::new(\n              std::io::ErrorKind::NotFound,\n              format!(\n                \"Failed to spawn '{}': No such cwd '{}'\",\n                command_name,\n                cwd.to_string_lossy()\n              ),\n            )\n            .into(),\n          );\n        }\n\n        #[allow(clippy::disallowed_methods, reason = \"requires real fs\")]\n        if !cwd.is_dir() {\n          return Err(\n            std::io::Error::new(\n              std::io::ErrorKind::NotFound,\n              format!(\n                \"Failed to spawn '{}': cwd is not a directory '{}'\",","sourceCodeStart":1102,"sourceCodeEnd":1138,"githubUrl":"https://github.com/denoland/deno/blob/a961cdec3b1948844414ebeecc697dcad76df2d1/ext/process/lib.rs#L1102-L1138","documentation":"Deno's process spawn wrapper (ext/process/lib.rs, backing Deno.Command and node:child_process) pre-validates the cwd option against the real filesystem before exec. If the configured working directory does not exist, spawn fails immediately with ErrorKind::NotFound and this message naming the program and the missing path, instead of surfacing an opaque exec error.","triggerScenarios":"new Deno.Command(prog, { cwd }) or child_process.spawn(prog, { cwd }) where cwd points to a nonexistent path: deleted directory, wrong relative path resolved against the parent's cwd, typo in config, or a path valid in dev but absent in the deployed image.","commonSituations":"Docker images missing the directory the app assumes; relative cwd like './build' when the process starts from a different directory; directories removed by a clean step; configs pointing at another machine's layout.","solutions":["Create the directory before spawning: await mkdir(cwd, { recursive: true }).","Resolve cwd to an absolute path (path.resolve) so it does not depend on the parent's current directory.","Validate with fs.existsSync/statSync().isDirectory() before spawn and fail fast with a clear message.","If the directory was deleted by a build step, fix the ordering so spawn happens after the artifact dir exists."],"exampleFix":"// before\nconst cmd = new Deno.Command(\"cargo\", { cwd: \"./target/bench\" }); // ENOENT if dir absent\n\n// after\nimport { ensureDir } from \"jsr:@std/fs\";\nawait ensureDir(\"./target/bench\");\nconst cmd = new Deno.Command(\"cargo\", { cwd: await Deno.realPath(\"./target/bench\") });","handlingStrategy":"validation","validationCode":"import { statSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\nconst cwd = resolve(opts.cwd ?? \".\");\nconst st = statSync(cwd, { throwIfNoEntry: false });\nif (!st) throw new Error(`cwd does not exist: ${cwd}`);\nif (!st.isDirectory()) throw new Error(`cwd is not a directory: ${cwd}`);","typeGuard":"import { statSync } from \"node:fs\";\nconst isUsableCwd = (p: string): p is string => { const st = statSync(p, { throwIfNoEntry: false }); return !!st?.isDirectory(); };","tryCatchPattern":"try { new Deno.Command(prog, { cwd }); } catch (e) { if (/No such cwd/.test(String(e))) throw new Error(`configured cwd missing — create it first: ${cwd}`); throw e; }","preventionTips":["Resolve cwd to an absolute path before passing it to spawn APIs.","mkdir -p the working directory in Dockerfiles/deploy scripts so the path always exists.","Assert configured cwd values once at startup with a clear error naming the config key."],"tags":["process","spawn","cwd","not-found","filesystem"],"backgroundTag":"working-directory-not-found","analyzedSha":"a961cdec3b1948844414ebeecc697dcad76df2d1","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}