{"record":{"id":"a22178863a3778e6","repo":"can1357/oh-my-pi","slug":"cannot-stat-file-error","errorCode":null,"errorMessage":"cannot stat {file}: {error}","messagePattern":"cannot stat (.+?): (.+?)","errorType":"error_code","errorClass":"StatError","httpStatus":null,"severity":"error","filePath":"crates/pi-builtins/src/stat.rs","lineNumber":150,"sourceCode":"for details about the options it supports.\";\n\n\t#[derive(Debug, Error)]\n\tenum StatError {\n\t\t#[error(\"Invalid quoting style: {style}\")]\n\t\tInvalidQuotingStyle { style: String },\n\t\t#[error(\"missing operand\\nTry 'stat --help' for more information.\")]\n\t\tMissingOperand,\n\t\t#[error(\"{directive}: invalid directive\")]\n\t\tInvalidDirective { directive: String },\n\t\t#[error(\"cannot read table of mounted file systems: {error}\")]\n\t\t#[cfg_attr(not(unix), allow(dead_code, reason = \"mount tables are unix-only\"))]\n\t\tCannotReadFilesystem { error: String },\n\t\t#[error(\"using '-' to denote standard input does not work in file system mode\")]\n\t\t#[cfg_attr(not(unix), allow(dead_code, reason = \"stdin filesystem mode is unix-only\"))]\n\t\tStdinFilesystemMode,\n\t\t#[error(\"cannot read file system information for {file}: {error}\")]\n\t\tCannotReadFilesystemInfo { file: String, error: String },\n\t\t#[error(\"cannot stat {file}: {error}\")]\n\t\tCannotStat { file: String, error: String },\n\t}\n\n\tmod options {\n\t\tpub const DEREFERENCE: &str = \"dereference\";\n\t\tpub const FILE_SYSTEM: &str = \"file-system\";\n\t\tpub const FORMAT: &str = \"format\";\n\t\tpub const PRINTF: &str = \"printf\";\n\t\tpub const TERSE: &str = \"terse\";\n\t\tpub const BSD_SHELL: &str = \"bsd-shell\";\n\t\tpub const BSD_TIMEFMT: &str = \"bsd-timefmt\";\n\t\tpub const FILES: &str = \"files\";\n\t}\n\n\t#[derive(Default, Debug, PartialEq, Eq, Clone, Copy)]\n\tstruct Flags {\n\t\talter: bool,\n\t\tzero:  bool,","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/crates/pi-builtins/src/stat.rs#L132-L168","documentation":"This error (crates/pi-builtins/src/stat.rs, CannotStat) is the generic failure of the stat builtin's default file mode: the stat/lstat call on the given path failed. The wrapped `error` contains the OS reason (usually ENOENT, EACCES, or ELOOP). This is the most common stat error and mirrors GNU stat's `cannot stat 'file'` message.","triggerScenarios":"Calling the stat utility with a path that does not exist, lacks a path-component's execute (search) permission, sits on an unreachable mount, or triggers symlink loops.","commonSituations":"Typos in the filename; running as a user without directory traversal permissions; a dangling symlink when not using dereference-aware logic; deleted files referenced by stale paths in scripts.","solutions":["Verify the path exists and is spelled correctly (`ls -ld <file>`).","Check permissions on every path component (need execute bit on directories): `namei -l <path>`.","If it is a symlink, inspect `readlink <file>`; use the dereference option (`-L`) as appropriate.","Handle the error in scripts: use `stat <file> ||` fallback so missing files don't abort pipelines."],"exampleFix":"// before\nstat /tmp/missing-file.txt  // cannot stat /tmp/missing-file.txt: No such file or directory\n\n// after\nls -ld /tmp/missing-file.txt || echo \"file absent; creating\"\ntouch /tmp/missing-file.txt\nstat /tmp/missing-file.txt","handlingStrategy":"validation","validationCode":"import { statSync } from 'node:fs';\nfunction pathIsStatable(p) {\n  try { statSync(p); return true; } catch { return false; }\n}","typeGuard":"function isCannotStatError(err) {\n  return err instanceof Error && err.message.startsWith('cannot stat ');\n}","tryCatchPattern":"try {\n  await stat.run([path]);\n} catch (err) {\n  if (String(err).startsWith('cannot stat ')) {\n    console.error(`skipping unreachable path ${path}: ${err}`);\n  } else throw err;\n}","preventionTips":["Check existence with ls/test before stat in scripts.","Verify execute permission on every directory in the path (namei -l).","Clean up dangling symlinks; use readlink to validate link targets."],"tags":["stat","filesystem","enoent","permissions"],"backgroundTag":"stat-no-such-file","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}