{"record":{"id":"3e0d03c4ff4cbc47","repo":"can1357/oh-my-pi","slug":"invalid-size-unit-unit","errorCode":null,"errorMessage":"invalid size unit: {unit}","messagePattern":"invalid size unit: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/pi-builtins/src/fd.rs","lineNumber":1324,"sourceCode":"\tif split == 0 {\n\t\treturn Err(io::Error::new(io::ErrorKind::InvalidInput, format!(\"invalid size: {value}\")));\n\t}\n\tlet count = rest[..split]\n\t\t.parse::<u64>()\n\t\t.map_err(|err| io::Error::new(io::ErrorKind::InvalidInput, err.to_string()))?;\n\tlet unit = rest[split..].to_ascii_lowercase();\n\tlet multiplier = match unit.as_str() {\n\t\t\"\" | \"b\" => 1,\n\t\t\"k\" => 1_000,\n\t\t\"m\" => 1_000_000,\n\t\t\"g\" => 1_000_000_000,\n\t\t\"t\" => 1_000_000_000_000,\n\t\t\"ki\" => 1_024,\n\t\t\"mi\" => 1_048_576,\n\t\t\"gi\" => 1_073_741_824,\n\t\t\"ti\" => 1_099_511_627_776,\n\t\t_ => {\n\t\t\treturn Err(io::Error::new(\n\t\t\t\tio::ErrorKind::InvalidInput,\n\t\t\t\tformat!(\"invalid size unit: {unit}\"),\n\t\t\t));\n\t\t},\n\t};\n\tlet bytes = count.checked_mul(multiplier).ok_or_else(|| {\n\t\tio::Error::new(io::ErrorKind::InvalidInput, format!(\"size is too large: {value}\"))\n\t})?;\n\tOk(SizeFilter { ordering, bytes })\n}\n\nfn parse_time_filter(value: &str) -> io::Result<SystemTime> {\n\tif let Some(timestamp) = value.strip_prefix('@') {\n\t\tlet seconds = timestamp\n\t\t\t.parse::<u64>()\n\t\t\t.map_err(|err| io::Error::new(io::ErrorKind::InvalidInput, err.to_string()))?;\n\t\treturn Ok(UNIX_EPOCH + Duration::from_secs(seconds));\n\t}","sourceCodeStart":1306,"sourceCodeEnd":1342,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/crates/pi-builtins/src/fd.rs#L1306-L1342","documentation":"The size spec's trailing unit (lowercased) must be one of: '' , b, k, m, g, t (decimal 1000-based) or ki, mi, gi, ti (binary 1024-based). Any other suffix — including 'kb', 'mb', 'kib', or a stray character between the digits and unit — throws this io::Error with ErrorKind::InvalidInput. The message reports the exact offending unit string.","triggerScenarios":"Passing '--size +10kb' (only 'k' or 'ki' accepted, not 'kb'), '+5MB' → unit 'mb' unknown, '+1Kib' → 'kib' unknown, or a value like '+10x' with a nonsense unit. Uppercase input is lowercased first, so case is not the issue — spelling is.","commonSituations":"Users habituated to fd/fd-find or du, which accept 'KB'/'KiB' two-letter forms; scripts carrying sizes from other tools ('1MiB'); copy-pasted sizes with hidden characters between number and unit; confusion between the decimal (k=1000) and binary (ki=1024) ladders.","solutions":["Use a bare unit letter for decimal sizes: b, k, m, g, t (e.g. '+10k' = 10,000 bytes)","Use the i-suffixed form for binary sizes: ki, mi, gi, ti (e.g. '+10ki' = 10,240 bytes)","Strip suffixes like 'B'/'iB' doubling: 'kb' → 'k', 'kib' → 'ki'","Pre-validate with a regex such as ^[+-]?(\\d+)(b|k|ki|m|mi|g|gi|t|ti)?$ before passing the value"],"exampleFix":"// before\nfd --size '+10kb'\n// after\nfd --size '+10k'   // decimal: 10,000 bytes\n// or\nfd --size '+10ki'  // binary: 10,240 bytes","handlingStrategy":"validation","validationCode":"const UNITS = new Set([\"\",\"b\",\"k\",\"m\",\"g\",\"t\",\"ki\",\"mi\",\"gi\",\"ti\"]);\nfunction validateSizeUnit(value: string): string | null {\n  const m = /^[+-]?\\d+(.*)$/.exec(value);\n  if (!m) return null; // different error path\n  const unit = m[1].toLowerCase();\n  if (!UNITS.has(unit)) return `invalid size unit: ${unit} (allowed: b k m g t ki mi gi ti)`;\n  return null;\n}","typeGuard":"function isValidSizeUnit(u: string): u is \"\"|\"b\"|\"k\"|\"m\"|\"g\"|\"t\"|\"ki\"|\"mi\"|\"gi\"|\"ti\" {\n  return [\"\",\"b\",\"k\",\"m\",\"g\",\"t\",\"ki\",\"mi\",\"gi\",\"ti\"].includes(u.toLowerCase());\n}","tryCatchPattern":"try {\n  await runFd({ size: value });\n} catch (err) {\n  if (err instanceof Error && err.message.startsWith(\"invalid size unit: \")) {\n    const unit = err.message.slice(\"invalid size unit: \".length);\n    console.error(`Unknown unit \"${unit}\". Use b|k|m|g|t (decimal) or ki|mi|gi|ti (binary). \"kb\"/\"kib\" are NOT accepted.`);\n  } else throw err;\n}","preventionTips":["Map foreign-tool suffixes before passing: kb→k, mb→m, KiB→ki, MiB→mi","Normalize the unit through lowercasing in your wrapper (the parser already lowercases, but spelling must still match)","Memorize the two ladders: b/k/m/g/t = ×1000; ki/mi/gi/ti = ×1024","Regex-gate sizes with ^[+-]?\\d+(b|k|ki|m|mi|g|gi|t|ti)?$"],"tags":["cli","size-parsing","unit-suffix","invalid-input"],"backgroundTag":"invalid-size-format","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}