{"id":"fb39d50a5e671d17","repo":"BurntSushi/ripgrep","slug":"invalid-format-for-size-which-should-be-a-no","errorCode":null,"errorMessage":"invalid format for size '{}', which should be a non-empty sequence of digits followed by an optional 'K', 'M' or 'G' suffix","messagePattern":"invalid format for size '(.+?)', which should be a non-empty sequence of digits followed by an optional 'K', 'M' or 'G' suffix","errorType":"validation","errorClass":"ParseSizeError","httpStatus":null,"severity":"error","filePath":"crates/cli/src/human.rs","lineNumber":48,"sourceCode":"        }\n    }\n\n    fn overflow(original: &str) -> ParseSizeError {\n        ParseSizeError {\n            original: original.to_string(),\n            kind: ParseSizeErrorKind::Overflow,\n        }\n    }\n}\n\nimpl std::error::Error for ParseSizeError {}\n\nimpl std::fmt::Display for ParseSizeError {\n    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {\n        use self::ParseSizeErrorKind::*;\n\n        match self.kind {\n            InvalidFormat => write!(\n                f,\n                \"invalid format for size '{}', which should be a non-empty \\\n                 sequence of digits followed by an optional 'K', 'M' or 'G' \\\n                 suffix\",\n                self.original\n            ),\n            InvalidInt(ref err) => write!(\n                f,\n                \"invalid integer found in size '{}': {}\",\n                self.original, err\n            ),\n            Overflow => write!(f, \"size too big in '{}'\", self.original),\n        }\n    }\n}\n\nimpl From<ParseSizeError> for std::io::Error {\n    fn from(size_err: ParseSizeError) -> std::io::Error {","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/BurntSushi/ripgrep/blob/3fce3b5bb0236da2df6d99672afb8a719642eca7/crates/cli/src/human.rs#L30-L66","documentation":"parse_human_readable_size returns ParseSizeErrorKind::InvalidFormat (the 'format' constructor) when the input has no leading ASCII digits (digits.is_empty()) OR when the suffix after the digits is anything other than empty/K/M/G. The Display impl prints the expected grammar so end users know the accepted shapes.","triggerScenarios":"Calling parse_human_readable_size with \"\", \"abc\", \"K\", \"-5\", \"12T\", \"12KB\", \"1.5M\", or any string whose digit-prefix is empty or whose trailing suffix is unrecognized.","commonSituations":"CLI flag parsing where a user passes --max-filesize with the wrong unit (T, KB, MiB), a stray sign, a decimal point, or trailing whitespace; config files copied from a tool that uses different size syntax.","solutions":["Use one of the accepted forms: a non-empty digit run optionally followed by exactly K, M, or G (e.g. \"512\", \"10M\", \"2G\").","Strip whitespace and reject decimals/signs before calling the parser, since neither is supported.","If you need T/KB/MiB units, pre-normalize the value to bytes yourself before passing a plain byte count."],"exampleFix":"// before\nlet n = parse_human_readable_size(\"1.5MiB\")?; // errors: invalid format\n\n// after\nlet n = parse_human_readable_size(\"1536M\")?; // accepted","handlingStrategy":"validation","validationCode":"fn looks_like_size(s: &str) -> bool {\n    let mut it = s.bytes();\n    if !it.next().is_some_and(|b| b.is_ascii_digit()) { return false; }\n    let suffix: String = s.bytes().skip_while(|b| b.is_ascii_digit()).map(|b| b as char).collect();\n    suffix.is_empty() || matches!(suffix.as_str(), \"K\" | \"M\" | \"G\")\n}","typeGuard":null,"tryCatchPattern":"let n = parse_human_readable_size(input);\nif let Err(e) = n { eprintln!(\"invalid size: {e}\"); return; }","preventionTips":["Document the accepted grammar (digits + optional single K/M/G) at every CLI flag that uses it.","Pre-validate with a regex like ^[0-9]+[KMG]?$, before calling the parser.","Normalize user input (trim whitespace, reject decimals/signs) upstream."],"tags":["size-parsing","cli","validation","human-readable"],"analyzedSha":"3fce3b5bb0236da2df6d99672afb8a719642eca7","analyzedAt":"2026-08-06T01:39:05.073Z","schemaVersion":2}