{"record":{"id":"db198d945af4ad97","repo":"can1357/oh-my-pi","slug":"0","errorCode":null,"errorMessage":"{0}","messagePattern":"\\{0\\}","errorType":"error_code","errorClass":"HeadError","httpStatus":null,"severity":"error","filePath":"crates/pi-builtins/src/head.rs","lineNumber":990,"sourceCode":"\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),\n\tAllButLastLines(u64),\n\tFirstBytes(u64),\n\tAllButLastBytes(u64),","sourceCodeStart":972,"sourceCodeEnd":1008,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/crates/pi-builtins/src/head.rs#L972-L1008","documentation":"HeadError::ParseError carries a free-form message (formatted as '{0}') produced when parsing head's command-line-style options fails, such as an invalid count value or malformed flag combination. The message text itself describes the specific parse problem.","triggerScenarios":"Invoking the head builtin with options that fail internal parsing, e.g. a non-numeric -n value, an unrecognized flag, or an argument combination the option parser rejects; the produced message is embedded in this variant.","commonSituations":"Scripts passing user-supplied counts like '-n abc'; duplicated/conflicting flags; copying CLI syntax that the in-process parser does not accept; forgotten argument values producing leftover tokens.","solutions":["Read the embedded message (the {0} payload) to identify the exact parse problem","Pass a valid numeric count, e.g. -n 10 or -c 1024","Validate option strings before invoking the builtin in embedded usage","Match only documented flags supported by this head implementation"],"exampleFix":"// before\nhead_opts([\"-n\", \"abc\"]);\n// after\nhead_opts([\"-n\", \"10\"]);","handlingStrategy":"validation","validationCode":"fn validate_head_args(args: &[&str]) -> Result<(), String> {\n\tlet mut i = 0;\n\twhile i < args.len() {\n\t\tif args[i] == \"-n\" || args[i] == \"-c\" {\n\t\t\tlet Some(v) = args.get(i + 1) else { return Err(format!(\"{} needs a value\", args[i])) };\n\t\t\tif v.parse::<u64>().is_err() { return Err(format!(\"{} expects a number, got '{v}'\", args[i])); }\n\t\t\ti += 2;\n\t\t} else { i += 1; }\n\t}\n\tOk(())\n}","typeGuard":null,"tryCatchPattern":"match head_result {\n\tErr(HeadError::ParseError(msg)) => eprintln!(\"bad head options: {msg}\"),\n\tErr(other) => return Err(other),\n\tOk(v) => /* ... */,\n}","preventionTips":["Sanitize user-supplied counts (numeric check) before building option arrays","Avoid string-concatenating flags; build argv arrays explicitly","Stick to documented flags of this head implementation"],"tags":["rust","argument-parsing","cli-options","thiserror"],"backgroundTag":"cli-option-parse-failed","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}