{"record":{"id":"8f52da4004c2056e","repo":"sharkdp/hexyl","slug":"failed-to-parse-length-arg-as-byte-count","errorCode":null,"errorMessage":"failed to parse `--length` arg {:?} as byte count","messagePattern":"failed to parse `--length` arg (.+?) as byte count","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/main.rs","lineNumber":360,"sourceCode":"            .map_err(|_| {\n                anyhow!(\n                    \"Failed to jump to the desired input position. \\\n                     This could be caused by a negative offset that is too large or by \\\n                     an input that is not seek-able (e.g. if the input comes from a pipe).\"\n                )\n            })?\n    } else {\n        0\n    };\n\n    let parse_byte_count = |s| -> Result<u64> {\n        Ok(parse_byte_offset(s, block_size)?\n            .assume_forward_offset_from_start()?\n            .into())\n    };\n\n    let mut reader = if let Some(ref length) = opt.length {\n        let length = parse_byte_count(length).context(anyhow!(\n            \"failed to parse `--length` arg {:?} as byte count\",\n            length\n        ))?;\n        Box::new(reader.take(length))\n    } else {\n        reader.into_inner()\n    };\n\n    let no_color = std::env::var_os(\"NO_COLOR\").is_some();\n    let show_color = match opt.color {\n        ColorWhen::Never => false,\n        ColorWhen::Always => !no_color,\n        ColorWhen::Force => true,\n        ColorWhen::Auto => {\n            if no_color {\n                false\n            } else {\n                supports_color::on(supports_color::Stream::Stdout)","sourceCodeStart":342,"sourceCodeEnd":378,"githubUrl":"https://github.com/sharkdp/hexyl/blob/6ecc29b9c8c84d08a7e860f7f69c22b113b480ea/src/main.rs#L342-L378","documentation":"The --length argument must parse as a byte count via parse_byte_count; on failure the error is wrapped with context 'failed to parse `--length` arg ... as byte count'.","triggerScenarios":"--length with malformed values like --length 5MBx, --length 1.5, --length '' , or an unsupported unit suffix.","commonSituations":"Typing decimal fractions where only integers are accepted; wrong unit spelling; shell variables containing whitespace or units from other tools (e.g. '5M' vs '5MiB' expectations).","solutions":["Pass an integer byte count or valid unit expression, e.g. --length 1024 or --length 4k","Strip whitespace/quotes from shell variables used for --length","Check the underlying parse error printed beneath the context message for the offending character"],"exampleFix":"// before\nb3sum --length 1.5k file\n// after\nb3sum --length 1536 file","handlingStrategy":"validation","validationCode":"[[ \"$len\" =~ ^[0-9]+(k|KiB|M|MiB|G|GiB)?$ ]] || { echo \"bad --length: $len\" >&2; exit 1; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use integer byte counts or documented units","Trim whitespace from variables","Avoid decimal fractions in --length"],"tags":["cli","parsing","invalid-argument"],"backgroundTag":"invalid-argument-format","analyzedSha":"6ecc29b9c8c84d08a7e860f7f69c22b113b480ea","analyzedAt":"2026-09-09T22:34:15.450Z","contentChangedAt":"2026-09-09T22:34:15.450Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}