{"record":{"id":"6c00a2db6f078b4a","repo":"coleam00/Archon","slug":"eacces","errorCode":"EACCES","errorMessage":"Failed to read version: permission denied reading package.json","messagePattern":"Failed to read version: permission denied reading package\\.json","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cli/src/commands/version.ts","lineNumber":44,"sourceCode":"  version: string;\n}\n\n/**\n * Get version for development mode (reads package.json)\n */\nasync function getDevVersion(): Promise<{ name: string; version: string }> {\n  // Read root package.json (monorepo version), not the CLI package's own\n  const pkgPath = join(SCRIPT_DIR, '../../../../package.json');\n\n  let content: string;\n  try {\n    content = await readFile(pkgPath, 'utf-8');\n  } catch (error) {\n    const err = error as NodeJS.ErrnoException;\n    if (err.code === 'ENOENT') {\n      throw new Error('Failed to read version: package.json not found (bad installation?)');\n    } else if (err.code === 'EACCES') {\n      throw new Error('Failed to read version: permission denied reading package.json');\n    }\n    throw new Error(`Failed to read version: ${err.message}`);\n  }\n\n  let pkg: PackageJson;\n  try {\n    pkg = JSON.parse(content) as PackageJson;\n  } catch (_error) {\n    throw new Error('Failed to read version: package.json is malformed');\n  }\n\n  return { name: pkg.name, version: pkg.version };\n}\n\n/**\n * Get the git commit hash at runtime (dev mode).\n * Returns 'unknown' if git is unavailable or the command fails.\n */","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/coleam00/Archon/blob/0773b9745896ef0612e709c80845a0f7db315b19/packages/cli/src/commands/version.ts#L26-L62","documentation":"getDevVersion reads package.json to report the version; when the OS rejects the read with EACCES (permission denied), it throws this translated error instead of leaking the raw errno. The file exists but the current user/process lacks read permission on it or a parent directory.","triggerScenarios":"devInfo -> getDevVersion calls readFile(pkgPath) and Node rejects with code 'EACCES': file owned by another user (e.g. installed with sudo, run as normal user), restrictive mode bits (0000/0444 with different owner), no execute permission on a parent directory, or running inside a container/sandbox lacking read access to the install prefix.","commonSituations":"Global install performed with sudo creating root-owned files while later commands run unprivileged; corporate-managed machines locking Program Files/privileged prefixes; SELinux/AppArmor denying access; umask mishaps in a custom install script.","solutions":["Check ownership/mode: `ls -l $(dirname <pkgPath>)/package.json` and `chmod a+r` it (or chown to your user).","Reinstall without sudo into a user-writable prefix (e.g. bun/npm user-global paths) to avoid root-owned installs.","If a security module (SELinux/AppArmor) denies the read, adjust policy or run from an allowed location.","Run the CLI as the same user that performed the installation."],"exampleFix":"// shell\n// before: -rw------- root root package.json, running as user -> EACCES\nsudo chown $(whoami) /path/to/install/package.json && chmod 644 /path/to/install/package.json","handlingStrategy":"validation","validationCode":"import { accessSync, constants } from 'node:fs';\ntry {\n  accessSync(pkgPath, constants.R_OK);\n} catch {\n  throw new Error(`Cannot read ${pkgPath} as user ${process.getuid?.()}: fix ownership/mode or reinstall without sudo`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  const info = await devInfo();\n} catch (err) {\n  if (err instanceof Error && err.message.includes('permission denied reading package.json')) {\n    // chmod a+r the file / chown to the running user, or reinstall into a user prefix\n  } else throw err;\n}","preventionTips":["Avoid sudo installs for tools you run as a normal user; use user-scoped global prefixes.","After sudo installs, chown the prefix back or set readable modes.","Check SELinux/AppArmor policies when running from nonstandard paths.","Run the CLI as the same user that owns the installation."],"tags":["filesystem","permissions","eacces","installation"],"backgroundTag":"permission-denied","analyzedSha":"0773b9745896ef0612e709c80845a0f7db315b19","analyzedAt":"2026-09-01T02:28:07.064Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}