can1357/oh-my-pi · error
invalid size: {value}
Error message
invalid size: {value} What it means
parse_size_filter splits a size spec (optionally prefixed with + or -) into a leading digit run and a trailing unit. When the string contains no leading digits at all — e.g. it starts directly with a unit letter or is empty after the sign — it cannot determine a count and throws this io::Error with ErrorKind::InvalidInput.
Source
Thrown at crates/pi-builtins/src/fd.rs:1307
.iter()
.map(|value| parse_size_filter(value))
.collect()
}
fn parse_size_filter(value: &str) -> io::Result<SizeFilter> {
let (ordering, rest) = if let Some(rest) = value.strip_prefix('+') {
(SizeOrdering::GreaterOrEqual, rest)
} else if let Some(rest) = value.strip_prefix('-') {
(SizeOrdering::LessOrEqual, rest)
} else {
(SizeOrdering::Equal, value)
};
let split = rest
.char_indices()
.find(|(_, ch)| !ch.is_ascii_digit())
.map_or(rest.len(), |(index, _)| index);
if split == 0 {
return Err(io::Error::new(io::ErrorKind::InvalidInput, format!("invalid size: {value}")));
}
let count = rest[..split]
.parse::<u64>()
.map_err(|err| io::Error::new(io::ErrorKind::InvalidInput, err.to_string()))?;
let unit = rest[split..].to_ascii_lowercase();
let multiplier = match unit.as_str() {
"" | "b" => 1,
"k" => 1_000,
"m" => 1_000_000,
"g" => 1_000_000_000,
"t" => 1_000_000_000_000,
"ki" => 1_024,
"mi" => 1_048_576,
"gi" => 1_073_741_824,
"ti" => 1_099_511_627_776,
_ => {
return Err(io::Error::new(
io::ErrorKind::InvalidInput,View on GitHub (pinned to 9690622007)
Solutions
- Prefix the size with a plain decimal integer, e.g. '+100mb', '-2k', '512b'
- Reorder unit-before-number mistakes: '+mb100' → '+100mb'
- Check that shell variables interpolating into the value are non-empty
- Replace fractional sizes with the equivalent integer in a smaller unit: '+0.5g' → '+500m'
Example fix
// before fd --size '+mb' // after fd --size '+100mb'
Defensive patterns
Strategy: validation
Validate before calling
function validateSize(value: string): string | null {
const m = /^[+-]?(\d+)(.*)$/.exec(value);
if (!m) return `invalid size: ${value} (need a leading integer, optional +/- prefix, optional unit)`;
return null;
}
// e.g. validateSize("+100mb") -> null; validateSize("+mb") -> error message Try / catch
try {
await runFd({ size: value });
} catch (err) {
if (err instanceof Error && err.message.startsWith("invalid size: ")) {
console.error(`Size must start with digits: ${err.message}. Example: +100m`);
} else throw err;
} Prevention
- Assert shell variables interpolated into size flags are non-empty and numeric
- Use a regex ^[+-]?\d+ as a gate before invoking
- Remember fractional sizes are unsupported — convert 0.5g to 500m
- Keep the sign prefix (+/-) attached to the number, not the unit
When it happens
Trigger: Passing a --size value with no numeric portion: '+' or '-' alone, '+mb' (unit before number), 'kb' with no count, or an empty string. Also triggered by non-digit leading characters such as '.5mb' (decimal points are not digits here).
Common situations: Users writing find-style sizes like '+1M' but accidentally reversing to '+M1'; copying a size filter with the number stripped by shell quoting/variable expansion ("+$SIZE" where SIZE is empty); attempting fractional sizes like '+0.5g' which the parser does not support.
Related errors
- unknown file type: {value}
- err.to_string() (size parse error)
- invalid size unit: {unit}
- size is too large: {value}
- 2
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/24450d3dc0818b48.
Report an issue: GitHub.