{"id":"0306286966815afd","repo":"sharkdp/fd","slug":"is-not-a-valid-size-constraint-see-fd-hel","errorCode":null,"errorMessage":"'{}' is not a valid size constraint. See 'fd --help'.","messagePattern":"'(.+?)' is not a valid size constraint\\. See 'fd --help'\\.","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/filter/size.rs","lineNumber":30,"sourceCode":"    Equals(u64),\n}\n\n// SI prefixes (powers of 10)\nconst KILO: u64 = 1000;\nconst MEGA: u64 = KILO * 1000;\nconst GIGA: u64 = MEGA * 1000;\nconst TERA: u64 = GIGA * 1000;\n\n// Binary prefixes (powers of 2)\nconst KIBI: u64 = 1024;\nconst MEBI: u64 = KIBI * 1024;\nconst GIBI: u64 = MEBI * 1024;\nconst TEBI: u64 = GIBI * 1024;\n\nimpl SizeFilter {\n    pub fn from_string(s: &str) -> anyhow::Result<Self> {\n        SizeFilter::parse_opt(s)\n            .ok_or_else(|| anyhow!(\"'{}' is not a valid size constraint. See 'fd --help'.\", s))\n    }\n\n    fn parse_opt(s: &str) -> Option<Self> {\n        let pattern =\n            SIZE_CAPTURES.get_or_init(|| Regex::new(r\"(?i)^([+-]?)(\\d+)(b|[kmgt]i?b?)$\").unwrap());\n        if !pattern.is_match(s) {\n            return None;\n        }\n\n        let captures = pattern.captures(s)?;\n        let limit_kind = captures.get(1).map_or(\"+\", |m| m.as_str());\n        let quantity = captures\n            .get(2)\n            .and_then(|v| v.as_str().parse::<u64>().ok())?;\n\n        let multiplier = match &captures.get(3).map_or(\"b\", |m| m.as_str()).to_lowercase()[..] {\n            v if v.starts_with(\"ki\") => KIBI,\n            v if v.starts_with('k') => KILO,","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/sharkdp/fd/blob/41532d114e2ba565fb5367d606c111b29b96450c/src/filter/size.rs#L12-L48","documentation":"Thrown by SizeFilter::from_string in src/filter/size.rs:30 when the input fails to match the regex '(?i)^([+-]?)(\\d+)(b|[kmgt]i?b?)$'. A valid --size argument needs an optional '+'/'-' sign, a decimal quantity, and a unit of b, k/m/g/t (optionally with 'i' for binary and trailing 'b'); anything else is rejected.","triggerScenarios":"Passing 'fd --size 9999' (no unit), 'fd --size +18' (no unit), 'fd --size +50a' (bad unit), 'fd --size 1bib' (invalid unit), or 'fd --size $10M' (currency char).","commonSituations":"Forgetting the unit suffix (the most common form); mixing up binary vs decimal prefixes; quoting mistakes that leave a shell '$' or stray space in the argument.","solutions":["Append a unit: 'fd --size +1k' or 'fd --size -100mib'.","Use '+' for minimum size and '-' for maximum size: 'fd --size +1g' (>= 1 GiB), 'fd --size -10k' (<= 10 KB).","Check the regex examples in 'fd --help' and confirm the whole token matches '<sign?><digits><unit>'."],"exampleFix":"// before\nfd --size 100\n\n// after\nfd --size -100k","handlingStrategy":"validation","validationCode":"# accept <[+-]?>,<digits>,<unit>  where unit in b|k|m|g|t with optional i/b\nif ! printf '%s' \"$SIZE\" | grep -Eq '^[+-]?[0-9]+(b|[kmgt]i?b?)$'; then\n  echo \"invalid --size: $SIZE\" >&2; exit 1\nfi\nfd --size \"$SIZE\"","typeGuard":"use regex::Regex;\nuse std::sync::OnceLock;\nfn is_valid_size(s: &str) -> bool {\n    static RE: OnceLock<Regex> = OnceLock::new();\n    RE.get_or_init(|| Regex::new(r\"(?i)^([+-]?)(\\d+)(b|[kmgt]i?b?)$\").unwrap())\n        .is_match(s)\n}","tryCatchPattern":null,"preventionTips":["Always include a unit (b/k/m/g/t, optionally with 'i' for binary).","Use '+' for minimum and '-' for maximum size; omit sign for exact.","Strip shell metacharacters before composing the --size argument."],"tags":["size-filter","parsing","cli-flag","regex"],"analyzedSha":"41532d114e2ba565fb5367d606c111b29b96450c","analyzedAt":"2026-08-06T01:39:28.509Z","schemaVersion":2}