can1357/oh-my-pi · error · SortError
cannot read: {}: {}
Error message
cannot read: {}: {} What it means
`SortError::ReadFailed` occurs when the sort builtin cannot read from an already-opened file, quoting the path and the stripped errno. Unlike OpenFailed, the open succeeded but a subsequent read operation failed (I/O error, EISDIR on read, hardware error).
Source
Thrown at crates/pi-builtins/src/sort.rs:2602
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())]
FileOperandsCombined { file: PathBuf },
View on GitHub (pinned to 9690622007)
Solutions
- Re-run the sort; transient network/IO errors often clear.
- Check filesystem health (`dmesg`, `smartctl`) if errors persist.
- Ensure no other process truncates/rewrites the file during the sort (snapshot or copy first).
- Copy the file to local disk before sorting if it lives on an unreliable network mount.
Example fix
// before sort /mnt/nfs/live.log // after cp /mnt/nfs/live.log /tmp/live.snapshot.log && sort /tmp/live.snapshot.log
Defensive patterns
Strategy: retry
Try / catch
// transient read errors warrant a bounded retry
for attempt in 1..=3 {
match run_sort() {
Err(SortError::ReadFailed { path, error }) => {
eprintln!("attempt {attempt}: read {} failed: {error}", path.display());
sleep(Duration::from_secs(2u64.pow(attempt - 1)));
}
other => { other?; break; }
}
} Prevention
- Snapshot inputs to local disk before sorting network-resident files.
- Avoid concurrent writers to files being sorted.
- Monitor filesystem health; persistent read errors indicate failing storage.
When it happens
Trigger: A read syscall on an input or temp file fails mid-sort — e.g. device I/O error, file truncated concurrently by another process, or attempting to read a special file that rejects reads.
Common situations: NFS/network filesystem staleness or timeouts; concurrent modification or truncation of the input while sorting; failing disk sectors.
Related errors
- write failed: {}: {}
- open failed: {}: {}
- 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/09e7bcae4525e07a.
Report an issue: GitHub.