{"record":{"id":"8e395d20df086313","repo":"yamadashy/repomix","slug":"invalid-size-input-expected-format-like-50","errorCode":null,"errorMessage":"Invalid size: '${input}'. Expected format like '500kb', '2mb', or '2.5mb' (case-insensitive).","messagePattern":"Invalid size: '(.+?)'\\. Expected format like '500kb', '2mb', or '2\\.5mb' \\(case-insensitive\\)\\.","errorType":"validation","errorClass":"RepomixError","httpStatus":null,"severity":"error","filePath":"src/shared/sizeParse.ts","lineNumber":8,"sourceCode":"import { RepomixError } from './errorHandle.js';\n\nconst SIZE_RE = /^\\s*(\\d+(?:\\.\\d+)?)\\s*(kb|mb)\\s*$/i;\n\nexport const parseHumanSizeToBytes = (input: string): number => {\n  const match = SIZE_RE.exec(input);\n  if (!match) {\n    throw new RepomixError(\n      `Invalid size: '${input}'. Expected format like '500kb', '2mb', or '2.5mb' (case-insensitive).`,\n    );\n  }\n\n  const amount = Number(match[1]);\n  if (!Number.isFinite(amount) || amount <= 0) {\n    throw new RepomixError(`Invalid size amount: '${match[1]}'. Must be a positive number.`);\n  }\n\n  const unit = match[2].toLowerCase();\n  const multiplier = unit === 'kb' ? 1024 : 1024 * 1024;\n  const bytes = Math.floor(amount * multiplier);\n\n  if (!Number.isSafeInteger(bytes)) {\n    throw new RepomixError(`Invalid size: '${input}'. Resulting byte value is too large.`);\n  }\n\n  return bytes;","sourceCodeStart":1,"sourceCodeEnd":26,"githubUrl":"https://github.com/yamadashy/repomix/blob/f465ad909315a22120636baf03fa5e28701a50cb/src/shared/sizeParse.ts#L1-L26","documentation":"parseHumanSizeToBytes parses human-readable size strings strictly matching /^\\s*(\\d+(?:\\.\\d+)?)\\s*(kb|mb)\\s*$/i. If the input doesn't match (wrong unit, no unit, negative, unsupported units like gb/b), it throws a RepomixError explaining the accepted format.","triggerScenarios":"Passing size config values (e.g. file-size limits) like '1gb', '500KB/s', 'kb' with no number, '1 B', '2 MB ' with tab handling okay but '2mib' wrong, or a plain integer without unit.","commonSituations":"Users copy sizes from other tools that accept gb or bytes ('52428800'); typos like '5OOkb'; assuming decimal suffixes (MiB) or byte-only input are supported.","solutions":["Convert the value to kb or mb, e.g. '1gb' -> '1024mb', raw bytes -> '50mb'","Match the format exactly: number plus kb/mb, e.g. '500kb', '2.5mb'","Fix typos (letters swapped for digits) in the size string"],"exampleFix":"// before\n{ \"output\": { \"truncateSize\": \"1gb\" } }\n// after\n{ \"output\": { \"truncateSize\": \"1024mb\" } }","handlingStrategy":"validation","validationCode":"const SIZE_RE = /^\\s*(\\d+(?:\\.\\d+)?)\\s*(kb|mb)\\s*$/i;\nif (!SIZE_RE.test(raw)) throw new Error(`'${raw}' must look like '500kb' or '2.5mb'`);","typeGuard":null,"tryCatchPattern":"import { parseHumanSizeToBytes } from 'repomix/shared';\ntry {\n  const bytes = parseHumanSizeToBytes(raw);\n} catch (e) {\n  if (String(e.message).startsWith('Invalid size:')) {\n    // normalize to kb/mb before writing into config\n  } else throw e;\n}","preventionTips":["Always express sizes in kb or mb ('1gb' -> '1024mb')","Validate size strings when generating config programmatically","Never pass bare byte counts or MiB units"],"tags":["config","validation","size-parsing"],"backgroundTag":"invalid-size-format","analyzedSha":"f465ad909315a22120636baf03fa5e28701a50cb","analyzedAt":"2026-08-29T01:27:42.024Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}