{"record":{"id":"0785922f66f9b599","repo":"paperclipai/paperclip","slug":"could-not-create-working-directory-cwd-rea","errorCode":null,"errorMessage":"Could not create working directory \"${cwd}\": ${reason}","messagePattern":"Could not create working directory \"(.+?)\": (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/adapter-utils/src/server-utils.ts","lineNumber":2452,"sourceCode":"  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 });\n    await assertDirectory();\n  } catch (err) {\n    const reason = err instanceof Error ? err.message : String(err);\n    throw new Error(`Could not create working directory \"${cwd}\": ${reason}`);\n  }\n}\n\nexport async function resolvePaperclipSkillsDir(\n  moduleDir: string,\n  additionalCandidates: string[] = [],\n): Promise<string | null> {\n  const candidates = [\n    ...PAPERCLIP_SKILL_ROOT_RELATIVE_CANDIDATES.map((relativePath) => path.resolve(moduleDir, relativePath)),\n    ...additionalCandidates.map((candidate) => path.resolve(candidate)),\n  ];\n  const seenRoots = new Set<string>();\n\n  for (const root of candidates) {\n    if (seenRoots.has(root)) continue;\n    seenRoots.add(root);\n    const isDirectory = await fs.stat(root).then((stats) => stats.isDirectory()).catch(() => false);\n    if (isDirectory) return root;","sourceCodeStart":2434,"sourceCodeEnd":2470,"githubUrl":"https://github.com/paperclipai/paperclip/blob/67001ec6eb96ae601aa27bc91d9b2415d665334a/packages/adapter-utils/src/server-utils.ts#L2434-L2470","documentation":"Thrown by ensureAbsoluteDirectory when createIfMissing was true, the path did not exist (ENOENT), and the subsequent fs.mkdir(cwd, {recursive:true}) or the post-mkdir assertDirectory itself threw. The wrapped reason is the underlying error message — typically EACCES (permission denied), EROFS (read-only filesystem), ENOSPC, or a parent path component that is a file.","triggerScenarios":"ensureAbsoluteDirectory(cwd, {createIfMissing:true}) where mkdir fails: the orchestrator user lacks write permission on the parent, the filesystem is read-only, the disk is full, or a parent segment is a regular file (ENOTDIR).","commonSituations":"Running as a user without write access to the target parent (e.g. /var/lib/...); container with a read-only rootfs or a read-only mount at the path; disk full; a parent like '/data' is a file not a directory; SELinux/AppArmor denial.","solutions":["Grant write permission on the parent directory to the running user (chown/chmod), or choose a writable location.","If on a read-only filesystem, mount a writable volume at or above the path.","Free disk space if ENOSPC, and check `reason` in the error for the exact errno.","Ensure no parent path component is a file (mkdir -p fails with ENOTDIR in that case) and fix the upstream layout."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Pre-check writability of the parent before relying on mkdir.\nimport { access } from 'node:fs/promises';\ntry { await access(path.dirname(cwd), fsConstants.W_OK); } catch { throw new Error(`parent of ${cwd} is not writable`); }","typeGuard":null,"tryCatchPattern":"try { await ensureAbsoluteDirectory(cwd, { createIfMissing: true }); } catch (err) { logger.error('cannot create working dir', { cwd, reason: (err as Error).message }); throw err; }","preventionTips":["Ensure the running user owns or can write the parent directory.","Mount a writable volume at read-only paths.","Free disk space and check errno in the wrapped reason."],"tags":["filesystem","permissions","working-directory","mkdir","eacces"],"backgroundTag":null,"analyzedSha":"67001ec6eb96ae601aa27bc91d9b2415d665334a","analyzedAt":"2026-08-12T12:05:45.408Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}