can1357/oh-my-pi · error
cannot stat {0}: No such file or directory
Error message
cannot stat {0}: No such file or directory What it means
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.
Source
Thrown at crates/pi-builtins/src/mv.rs:53
backup_control::{self, BackupMode, source_is_target_backup},
display::Quotable,
fs::{
MissingHandling, ResolveMode, are_hardlinks_or_one_way_symlink_to_same_file,
are_hardlinks_to_same_file, canonicalize, path_ends_with_terminator,
},
update_control::{self, UpdateMode},
};
use crate::host::{Host, Utility, format_usage, matches_parser, util};
#[cfg(unix)]
use self::hardlink::{
HardlinkGroupScanner, HardlinkOptions, HardlinkTracker, create_hardlink_context,
with_optional_hardlink_context,
};
#[derive(Debug, Error)]
enum MvError {
#[error("cannot stat {0}: No such file or directory")]
NoSuchFile(String),
#[error("cannot stat {0}: Not a directory")]
CannotStatNotADirectory(String),
#[error("{0} and {1} are the same file")]
SameFile(String, String),
#[error("cannot move {0} to a subdirectory of itself, {1}")]
SelfTargetSubdirectory(String, String),
#[error("cannot overwrite directory {0} with non-directory")]
DirectoryToNonDirectory(String),
#[error("cannot overwrite non-directory {1} with directory {0}")]
NonDirectoryToDirectory(String, String),
#[error("target {0}: Not a directory")]
NotADirectory(String),
#[error("target directory {0}: Not a directory")]
TargetNotADirectory(String),
#[error("failed to access {0}: Not a directory")]
FailedToAccessNotADirectory(String),
}View on GitHub (pinned to 9690622007)
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.
Example fix
# before mv "$LOG_DIR/app.log" archive/ # after if [ -e "$LOG_DIR/app.log" ]; then mv "$LOG_DIR/app.log" archive/; else echo "app.log missing" >&2; fi
Defensive patterns
Strategy: try-catch
Validate before calling
[ -e "$src" ] || { echo "mv: cannot stat '$src': No such file or directory" >&2; exit 1; } Try / catch
mv "$src" "$dst" || { echo "move of $src failed" >&2; exit 1; } # check exit status; message already names the missing file Prevention
- 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.
When it happens
Trigger: `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).
Common situations: 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.
Related errors
- cannot stat {0}: Not a directory
- {0} and {1} are the same file
- cannot move {0} to a subdirectory of itself, {1}
- cannot overwrite directory {0} with non-directory
- cannot overwrite non-directory {1} with directory {0}
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/fb88142607b7526d.
Report an issue: GitHub.