{"record":{"id":"89b0e502545f6a7e","repo":"can1357/oh-my-pi","slug":"error-reading","errorCode":null,"errorMessage":"error reading {}: {}","messagePattern":"error reading (.+?): (.+?)","errorType":"error_code","errorClass":"HeadError","httpStatus":null,"severity":"error","filePath":"crates/pi-builtins/src/head.rs","lineNumber":987,"sourceCode":"\t#[test]\n\tfn test_more_lines() {\n\t\tlet input_reader = std::io::Cursor::new(\"a\\nb\\nc\\n\");\n\t\tlet output_reader = BufReader::new(take_lines(input_reader, 4, b'\\n'));\n\t\tlet mut iter = output_reader.lines().map(|l| l.unwrap());\n\t\tassert_eq!(Some(String::from(\"a\")), iter.next());\n\t\tassert_eq!(Some(String::from(\"b\")), iter.next());\n\t\tassert_eq!(Some(String::from(\"c\")), iter.next());\n\t\tassert_eq!(None, iter.next());\n\t}\n}\n}\n\nuse take::{copy_all_but_n_bytes, copy_all_but_n_lines, take_lines};\n\n#[derive(Error, Debug)]\nenum HeadError {\n\t/// Wrapper around `io::Error`\n\t#[error(\"error reading {}: {}\", name.quote(), err)]\n\tIo { name: PathBuf, err: io::Error },\n\n\t#[error(\"{0}\")]\n\tParseError(String),\n\n\t#[error(\"number of -bytes or -lines is too large\")]\n\tNumTooLarge(#[from] TryFromIntError),\n\n\n\t#[error(\"{0}\")]\n\tMatchOption(String),\n}\n\ntype HeadResult<T> = Result<T, HeadError>;\n\n#[derive(Debug, PartialEq)]\nenum Mode {\n\tFirstLines(u64),","sourceCodeStart":969,"sourceCodeEnd":1005,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/crates/pi-builtins/src/head.rs#L969-L1005","documentation":"HeadError::Io wraps any io::Error encountered while reading an input file during the head builtin's execution, formatting it as 'error reading <name>: <err>' with the path shell-quoted. It surfaces underlying OS-level read failures (file not found, permission denied, etc.) with the offending file's name attached.","triggerScenarios":"Calling the head builtin with a path that does not exist, lacks read permission, or where the underlying reader returns an I/O error mid-read (e.g. device errors, broken pipes on special files).","commonSituations":"Typos in file paths; reading files owned by another user; operating on dangling symlinks; passing directories where files are expected; network/special files that error during read.","solutions":["Verify the file path exists and is spelled correctly (ls the directory)","Check read permissions on the file (ls -l) and adjust with chmod/chown as appropriate","Inspect the wrapped inner err message for the precise OS-level cause","Handle the error variant in your caller to report or skip unreadable files gracefully"],"exampleFix":"// before\nhead(\"/var/log/missing.log\", 10);\n// after\nlet path = PathBuf::from(\"/var/log/app.log\");\nif path.exists() { head(&path, 10); }","handlingStrategy":"try-catch","validationCode":"// pre-check before invoking head\nif !std::path::Path::new(path).is_file() {\n\teprintln!(\"cannot read {path}: not a readable file\");\n}","typeGuard":null,"tryCatchPattern":"match head_result {\n\tErr(HeadError::Io { name, err }) => eprintln!(\"skipping {}: {err}\", name.display()),\n\tErr(other) => return Err(other),\n\tOk(v) => /* ... */,\n}","preventionTips":["Check path existence and permissions before passing files to head","Expand and normalize paths (avoid dangling symlinks) in scripts","Wrap shared-file reads with retry/backoff if files may be transiently locked"],"tags":["rust","io","file-read","thiserror"],"backgroundTag":"file-read-failed","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}