can1357/oh-my-pi · error · SortError
open failed: {}: {}
Error message
open failed: {}: {} What it means
`SortError::OpenFailed` is raised when the sort builtin cannot open a named file operand, quoting the path and the stripped errno (e.g. No such file or directory, Permission denied). It wraps the std::io::Error from the open call.
Source
Thrown at crates/pi-builtins/src/sort.rs:2599
// The automatic buffer heuristics clamp to this range to avoid
// over-committing memory on constrained systems while still keeping
// reasonably large chunks for typical workloads.
const MIN_AUTOMATIC_BUF_SIZE: usize = 512 * 1024; // 512 KiB
const FALLBACK_AUTOMATIC_BUF_SIZE: usize = 32 * 1024 * 1024; // 32 MiB
const MAX_AUTOMATIC_BUF_SIZE: usize = 1024 * 1024 * 1024; // 1 GiB
#[derive(Debug, Error)]
pub enum SortError {
#[error("{0}")]
Message(String),
#[error("write failed: {}: {}", .path.maybe_quote(), strip_errno(.error))]
WriteFailed { path: OsString, error: std::io::Error },
#[error("{}", format_disorder(.file, .line_number, .line, .silent))]
Disorder { file: OsString, line_number: usize, line: String, silent: bool },
#[error("open failed: {}: {}", .path.maybe_quote(), strip_errno(.error))]
OpenFailed { path: PathBuf, error: std::io::Error },
#[error("cannot read: {}: {}", .path.maybe_quote(), strip_errno(.error))]
ReadFailed { path: PathBuf, error: std::io::Error },
#[error("failed to open temporary file: {}", strip_errno(.error))]
OpenTmpFileFailed { error: std::io::Error },
#[error("could not run compress program '{}': {}", .prog, strip_errno(.error))]
CompressProgExecutionFailed { prog: String, error: std::io::Error },
#[error("{} terminated abnormally", .prog.quote())]
CompressProgTerminatedAbnormally { prog: String },
#[error("cannot create temporary file in {}:", .path.quote())]
TmpFileCreationFailed { path: PathBuf },
#[error("extra operand {}\nfile operands cannot be combined with --files0-from\nTry 'sort --help' for more information.", .file.quote())]View on GitHub (pinned to 9690622007)
Solutions
- Verify the path exists and is a regular file (`ls -l <path>`).
- Check permissions on the file and its parent directories.
- Use an absolute path or correct the working directory.
- If the file may legitimately be absent, fall back to reading stdin (`-` or piping).
Example fix
// before sort data.txt # file in another directory // after sort ./logs/data.txt
Defensive patterns
Strategy: validation
Validate before calling
for f in input_files {
match std::fs::metadata(f) {
Ok(m) if m.is_file() => {}
Ok(_) => eprintln!("{f} is not a regular file"),
Err(e) => eprintln!("cannot access {f}: {e}"),
}
} Try / catch
match sort_result {
Err(SortError::OpenFailed { path, error }) => {
eprintln!("cannot open {}: {error}", path.display());
}
Err(e) => eprintln!("sort: {e}"),
Ok(_) => {}
} Prevention
- Validate file operands exist and are readable before sorting.
- Use absolute paths or fix the working directory in scripts.
- Fall back to stdin ('-') when input may legitimately be absent.
When it happens
Trigger: Passing a file operand whose path does not exist, is misspelled, is a directory, or lacks read permission to the sort builtin.
Common situations: Typos in paths; relative paths evaluated from the wrong working directory; file deleted between listing and sorting; reading from a path that requires elevated permissions.
Understand the failure class
Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.
Related errors
- write failed: {}: {}
- cannot read: {}: {}
- cannot create temporary file in {}:
- Too many levels of symbolic links
- {}: {error}
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/e3df96cddeceb399.
Report an issue: GitHub.