{"record":{"id":"9a4cf9e883beafa2","repo":"can1357/oh-my-pi","slug":"unable-to-determine-an-accessible-working-director","errorCode":null,"errorMessage":"Unable to determine an accessible working directory","messagePattern":"Unable to determine an accessible working directory","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"packages/utils/src/dirs.ts","lineNumber":200,"sourceCode":"let projectDir: string | undefined;\n\n/** Get the project directory. */\nexport function getProjectDir(): string {\n\tif (projectDir === undefined) {\n\t\ttry {\n\t\t\tprojectDir = standardizeMacOSPath(process.cwd());\n\t\t} catch {\n\t\t\tconst candidates = [process.env.PWD, os.homedir(), os.tmpdir()];\n\t\t\tfor (const candidate of candidates) {\n\t\t\t\tif (!candidate || !path.isAbsolute(candidate)) continue;\n\t\t\t\ttry {\n\t\t\t\t\tprocess.chdir(candidate);\n\t\t\t\t\tprojectDir = standardizeMacOSPath(candidate);\n\t\t\t\t\tbreak;\n\t\t\t\t} catch {}\n\t\t\t}\n\t\t\tif (projectDir === undefined) {\n\t\t\t\tthrow new Error(\"Unable to determine an accessible working directory\");\n\t\t\t}\n\t\t}\n\t}\n\treturn projectDir;\n}\n\n/** Set the project directory. */\nexport function setProjectDir(dir: string): void {\n\tconst resolved = standardizeMacOSPath(path.resolve(dir));\n\tprocess.chdir(resolved);\n\tprojectDir = resolved;\n}\n\n/** Reset the cached project directory (test seam). */\nexport function __resetProjectDirCacheForTests(): void {\n\tprojectDir = undefined;\n}\n","sourceCodeStart":182,"sourceCodeEnd":218,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/utils/src/dirs.ts#L182-L218","documentation":"getProjectDir() resolves the project directory by probing candidate working directories and chdir-ing into the first accessible one. If every candidate throws (e.g. deleted or permission-denied directories) and no project dir can be established, it throws this error. All downstream helpers (cwd, resolveTargetDir, absolutePath, component, makeMarketplaceManager, actionClient) depend on it, so nothing that needs a working directory can proceed.","triggerScenarios":"Calling any API that resolves the project dir (cwd(), resolveTargetDir(), absolutePath(), component(), makeMarketplaceManager(), actionClient) when the current working directory and all fallback candidates are inaccessible: deleted cwd, no read/execute permission, or running from a nonexistent directory.","commonSituations":"A shell or process manager spawned the process after its cwd was deleted (common with rm -rf of the launch dir); running inside a container with an invalid WORKDIR; permission-stripped sandbox environments; NFS/network mounts that dropped; launching from a path that no longer exists after a checkout switch.","solutions":["Check that the process's current working directory exists and is accessible: run `pwd`/`ls` from the same context that launched the process.","Relaunch the process from a valid, existing directory (e.g. `cd /path/to/project && omp ...`).","Fix permissions on the directory (chmod/chown) so the process user can read and execute it.","If the cwd was deleted at runtime, set an explicit project/config root env var or start from a stable directory instead of a temporary one."],"exampleFix":"// before (launched from a dir that was deleted)\n$ cd /tmp/build && rm -rf /tmp/build &\n$ omp  // throws: Unable to determine an accessible working directory\n\n// after\n$ cd ~/projects/myapp && omp","handlingStrategy":"fallback","validationCode":"import { existsSync, accessSync, constants } from \"node:fs\";\nfunction isAccessibleDir(p: string): boolean {\n  try { accessSync(p, constants.R_OK | constants.X_OK); return true; } catch { return false; }\n}\nif (!isAccessibleDir(process.cwd())) {\n  process.chdir(isAccessibleDir(\"/tmp\") ? \"/tmp\" : os.homedir());\n}","typeGuard":null,"tryCatchPattern":"try {\n  const dir = getProjectDir();\n} catch (err) {\n  if (err instanceof Error && err.message === \"Unable to determine an accessible working directory\") {\n    process.chdir(os.tmpdir()); // or fail fast with a clear startup message\n  } else throw err;\n}","preventionTips":["Launch the process from a directory you know exists; avoid deleted/temporary directories.","Verify the container/daemon WORKDIR exists before startup.","Check permissions (r+x) on the launch directory for the running user.","Guard against cwd deletion in long-lived processes by re-entering a stable directory after cleanup jobs."],"tags":["filesystem","working-directory","startup","environment"],"backgroundTag":"invalid-working-directory","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}