can1357/oh-my-pi · error · SortError
{}
Error message
{} What it means
`SortError::Disorder` reports that input lines violated the expected ordering, formatted via `format_disorder` with the file, line number, offending line, and a silent flag. The sort builtin raises it when operating in a mode that verifies order (e.g. `-c`/check) and the input is not sorted.
Source
Thrown at crates/pi-builtins/src/sort.rs:2596
const NEGATIVE: &u8 = &b'-';
const POSITIVE: &u8 = &b'+';
// 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())]View on GitHub (pinned to 9690622007)
Solutions
- Sort the file first (`sort file`) or regenerate the input in sorted order.
- Ensure the same sort key/collation settings are used when producing and checking (set LC_ALL consistently, e.g. LC_ALL=C).
- If the disorder is expected, use `-m` (merge) or remove the check flag.
- Check the reported line number to find the first offending record and fix data upstream.
Example fix
// before sort -c data.txt # data.txt unsorted // after LC_ALL=C sort data.txt > data.sorted.txt && LC_ALL=C sort -c data.sorted.txt
Defensive patterns
Strategy: validation
Validate before calling
// pre-check ordering with the same collation used by sort
let status = std::process::Command::new("sort")
.args(["-c", path])
.env("LC_ALL", "C")
.status()?;
if !status.success() { eprintln!("{path} is not sorted (LC_ALL=C)"); } Try / catch
match sort_result {
Err(SortError::Disorder { file, line_number, line, silent }) => {
eprintln!("{}:{}: disorder: {}", file.display(), line_number, line);
}
Err(e) => eprintln!("sort: {e}"),
Ok(_) => {}
} Prevention
- Generate inputs with the same LC_ALL/collation used to check them.
- Standardize on LC_ALL=C for deterministic ordering in pipelines.
- Sort data before enabling any check (-c) mode.
When it happens
Trigger: Running sort in check mode (`sort -c`) against an unsorted file, causing the first out-of-order line to be reported.
Common situations: Validating that a pipeline output is sorted before consuming it; CI checks asserting sorted data files; a locale change (LC_ALL) making previously 'sorted' data appear out of order.
Related errors
- Unsupported language '{value}'. Supported: {}
- Unable to infer language from file extension: {}. Specify `l
- Invalid pattern: {err}
- Failed to load tree-sitter language: {err}
- err.to_string() (invalid glob pattern)
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/70515ff88fe57fa5.
Report an issue: GitHub.