{"record":{"id":"fb88142607b7526d","repo":"can1357/oh-my-pi","slug":"cannot-stat-0-no-such-file-or-directory","errorCode":null,"errorMessage":"cannot stat {0}: No such file or directory","messagePattern":"cannot stat (.+?): No such file or directory","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/pi-builtins/src/mv.rs","lineNumber":53,"sourceCode":"\tbackup_control::{self, BackupMode, source_is_target_backup},\n\tdisplay::Quotable,\n\tfs::{\n\t\tMissingHandling, ResolveMode, are_hardlinks_or_one_way_symlink_to_same_file,\n\t\tare_hardlinks_to_same_file, canonicalize, path_ends_with_terminator,\n\t},\n\tupdate_control::{self, UpdateMode},\n};\n\nuse crate::host::{Host, Utility, format_usage, matches_parser, util};\n#[cfg(unix)]\nuse self::hardlink::{\n\tHardlinkGroupScanner, HardlinkOptions, HardlinkTracker, create_hardlink_context,\n\twith_optional_hardlink_context,\n};\n\n#[derive(Debug, Error)]\nenum MvError {\n\t#[error(\"cannot stat {0}: No such file or directory\")]\n\tNoSuchFile(String),\n\t#[error(\"cannot stat {0}: Not a directory\")]\n\tCannotStatNotADirectory(String),\n\t#[error(\"{0} and {1} are the same file\")]\n\tSameFile(String, String),\n\t#[error(\"cannot move {0} to a subdirectory of itself, {1}\")]\n\tSelfTargetSubdirectory(String, String),\n\t#[error(\"cannot overwrite directory {0} with non-directory\")]\n\tDirectoryToNonDirectory(String),\n\t#[error(\"cannot overwrite non-directory {1} with directory {0}\")]\n\tNonDirectoryToDirectory(String, String),\n\t#[error(\"target {0}: Not a directory\")]\n\tNotADirectory(String),\n\t#[error(\"target directory {0}: Not a directory\")]\n\tTargetNotADirectory(String),\n\t#[error(\"failed to access {0}: Not a directory\")]\n\tFailedToAccessNotADirectory(String),\n}","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/crates/pi-builtins/src/mv.rs#L35-L71","documentation":"GNU-compatible `mv` error (`MvError::NoSuchFile`, crates/pi-builtins/src/mv.rs:53). Raised when `symlink_metadata` fails on a source operand: the file does not exist. With one source+target (`handle_two_paths`) the source is quoted in the message; with multiple sources (`move_files_into_dir`) the error is shown and the remaining files are still processed.","triggerScenarios":"`mv nonexistent.txt dest/`; a multi-file `mv a.txt b.txt target/` where one source is missing (each missing source logs this error and the move continues); a source path whose parent directory does not exist (unless the source ends with a trailing `/`, which yields `CannotStatNotADirectory` instead).","commonSituations":"Typoed or wrong-case filenames; scripts building paths from variables that were never set; files removed by a prior pipeline step before `mv` runs; relative paths executed from an unexpected working directory.","solutions":["Verify the source path exists before moving: `test -e \"$src\" && mv \"$src\" \"$dst\"` or `mv \"$src\" \"$dst\" 2>/dev/null || echo missing`.","Fix typos and check filename casing (case-sensitive filesystems).","Print/`set -x` the expanded path to catch unset or mis-joined variables.","For multi-source moves, list files explicitly or use a glob that matches at least one file so only existing paths are passed."],"exampleFix":"# before\nmv \"$LOG_DIR/app.log\" archive/\n# after\nif [ -e \"$LOG_DIR/app.log\" ]; then mv \"$LOG_DIR/app.log\" archive/; else echo \"app.log missing\" >&2; fi","handlingStrategy":"try-catch","validationCode":"[ -e \"$src\" ] || { echo \"mv: cannot stat '$src': No such file or directory\" >&2; exit 1; }","typeGuard":null,"tryCatchPattern":"mv \"$src\" \"$dst\" || { echo \"move of $src failed\" >&2; exit 1; }  # check exit status; message already names the missing file","preventionTips":["Test -e/-f source paths before moving, especially for computed paths.","Quote all path variables to avoid split/join surprises.","In multi-source moves, remember missing sources are reported but do not abort the rest — audit stderr.","Run scripts from a known working directory or use absolute paths."],"tags":["filesystem","mv","missing-file","stat"],"backgroundTag":"no-such-file-or-directory","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}