{"record":{"id":"319cb2da364d14cc","repo":"can1357/oh-my-pi","slug":"2-319cb2","errorCode":"2","errorMessage":"invalid line width: '{0}'","messagePattern":"invalid line width: '(.+?)'","errorType":"error_code","errorClass":"LsError","httpStatus":null,"severity":"error","filePath":"crates/pi-builtins/src/ls.rs","lineNumber":3677,"sourceCode":"fn os_str_starts_with(haystack: &OsStr, needle: &[u8]) -> bool {\n\tos_bytes_lossy(haystack).starts_with(needle)\n}\n\nfn write_os_str<W: Write>(writer: &mut W, string: &OsStr) -> std::io::Result<()> {\n\twriter.write_all(&os_bytes_lossy(string))\n}\n}\n\nuse colors::StyleManager;\npub use config::{Config, options};\nuse config::{Dereference, Files, Sort, options::QUOTING_STYLE};\nuse dired::DiredOutput;\npub use display::Format;\nuse display::{display_items, display_size, should_display, show_dir_name};\n\n#[derive(Error, Debug)]\nenum LsError {\n\t#[error(\"invalid line width: '{0}'\")]\n\tInvalidLineWidth(String),\n\n\t#[error(\"general io error: {0}\")]\n\tIOError(#[from] std::io::Error),\n\n\t#[error(\"{}\", match .1.kind() {\n\t\tErrorKind::NotADirectory => format!(\"cannot access {}: Not a directory\", .0.quote()),\n\t\tErrorKind::NotFound => format!(\"cannot access {}: No such file or directory\", .0.quote()),\n\t\tErrorKind::PermissionDenied => match .1.raw_os_error().unwrap_or(1) {\n\t\t\t1 => format!(\"cannot access {}: Operation not permitted\", .0.quote()),\n\t\t\t_ => if *.3 {\n\t\t\t\tformat!(\"cannot open directory {}: Permission denied\", .0.quote())\n\t\t\t} else {\n\t\t\t\tformat!(\"cannot open file {}: Permission denied\", .0.quote())\n\t\t\t},\n\t\t},\n\t\t_ => if 9 == .1.raw_os_error().unwrap_or(1) {\n\t\t\tformat!(\"cannot open directory {}: Bad file descriptor\", .0.quote())","sourceCodeStart":3659,"sourceCodeEnd":3695,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/crates/pi-builtins/src/ls.rs#L3659-L3695","documentation":"The ls builtin's InvalidLineWidth variant fires when the value supplied for line width (e.g. via a width/line-width option) cannot be parsed as a valid width. The offending string is echoed back so the user can see what was rejected. The process exits with code 2, matching GNU ls's usage-error convention.","triggerScenarios":"Passing a non-numeric or malformed value to the line-width option, e.g. `ls --width=abc` or an empty string.","commonSituations":"Config files or env vars supplying a width with units ('80ch') or whitespace; scripts interpolating an unset variable producing an empty width.","solutions":["Pass a plain positive integer for the width option","Validate/trim the width value before passing it","Remove the width option to use the terminal's default width"],"exampleFix":"// before\nls(&host, &[\"--width=80ch\", \".\"])?;\n// after\nls(&host, &[\"--width=80\", \".\"])?;","handlingStrategy":"validation","validationCode":"fn validate_width(w: &str) -> Result<u32, String> {\n    let t = w.trim();\n    t.parse::<u32>().map_err(|_| format!(\"invalid line width: '{w}'\")).and_then(|n| if n > 0 { Ok(n) } else { Err(format!(\"invalid line width: '{w}'\")) })\n}","typeGuard":null,"tryCatchPattern":"match ls(&host, args) {\n    Err(e) if e.to_string().starts_with(\"invalid line width\") => {\n        eprintln!(\"width must be a positive integer; using default\");\n        ls(&host, &[\".\"])?;\n    }\n    other => other?,\n}","preventionTips":["Pass only plain positive integers to width options","Trim and validate width strings from config/env before use","Guard against empty strings from unset variables"],"tags":["cli","ls","argument-validation","exit-code-2"],"backgroundTag":"invalid-argument-value","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}