{"record":{"id":"7175a170c18c1213","repo":"paperclipai/paperclip","slug":"working-directory-is-not-a-directory-cwd","errorCode":null,"errorMessage":"Working directory is not a directory: \"${cwd}\"","messagePattern":"Working directory is not a directory: \"(.+?)\"","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/adapter-utils/src/server-utils.ts","lineNumber":2430,"sourceCode":"\nexport function ensurePathInEnv(env: NodeJS.ProcessEnv): NodeJS.ProcessEnv {\n  if (typeof env.PATH === \"string\" && env.PATH.length > 0) return env;\n  if (typeof env.Path === \"string\" && env.Path.length > 0) return env;\n  return { ...env, PATH: defaultPathForPlatform() };\n}\n\nexport async function ensureAbsoluteDirectory(\n  cwd: string,\n  opts: { createIfMissing?: boolean } = {},\n) {\n  if (!path.isAbsolute(cwd)) {\n    throw new Error(`Working directory must be an absolute path: \"${cwd}\"`);\n  }\n\n  const assertDirectory = async () => {\n    const stats = await fs.stat(cwd);\n    if (!stats.isDirectory()) {\n      throw new Error(`Working directory is not a directory: \"${cwd}\"`);\n    }\n  };\n\n  try {\n    await assertDirectory();\n    return;\n  } catch (err) {\n    const code = (err as NodeJS.ErrnoException).code;\n    if (!opts.createIfMissing || code !== \"ENOENT\") {\n      if (code === \"ENOENT\") {\n        throw new Error(`Working directory does not exist: \"${cwd}\"`);\n      }\n      throw err instanceof Error ? err : new Error(String(err));\n    }\n  }\n\n  try {\n    await fs.mkdir(cwd, { recursive: true });","sourceCodeStart":2412,"sourceCodeEnd":2448,"githubUrl":"https://github.com/paperclipai/paperclip/blob/67001ec6eb96ae601aa27bc91d9b2415d665334a/packages/adapter-utils/src/server-utils.ts#L2412-L2448","documentation":"Thrown by ensureAbsoluteDirectory's assertDirectory when the path exists but fs.stat reports it is not a directory (e.g. it is a regular file, socket, or symlink to a file). The working directory must be an actual directory for spawning and file ops, so a file-at-that-path is rejected.","triggerScenarios":"ensureAbsoluteDirectory called with an absolute cwd that resolves to an existing non-directory entry — most often a file created earlier with the same name (e.g. a lock file, a build artifact, a mistakenly-created file instead of folder).","commonSituations":"A previous step wrote a file named identically to the intended directory (e.g. 'build' is a file); a symlink points at a file; a socket/device node occupies the path; the path collides with an artifact like 'dist'.","solutions":["Inspect the path with `ls -la <cwd>` to see whether it is a file or a bad symlink, then remove or rename it.","If a build step produced a file where a directory is expected, fix that step to mkdir instead of write.","Choose a non-colliding directory name for the working directory.","Resolve symlinks (fs.realpath) earlier to detect a file target before calling ensureAbsoluteDirectory."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const st = await fs.stat(cwd);\nif (!st.isDirectory()) {\n  throw new Error(`cwd is not a directory: ${cwd} (mode ${st.mode})`);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check for name collisions between files and intended directories in your layout.","Resolve symlinks early to detect file targets.","Use distinct names for artifacts vs working directories."],"tags":["filesystem","path","working-directory","validation"],"backgroundTag":null,"analyzedSha":"67001ec6eb96ae601aa27bc91d9b2415d665334a","analyzedAt":"2026-08-12T12:05:45.408Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}