{"record":{"id":"f1a6092a19714921","repo":"yamadashy/repomix","slug":"invalid-size-amount-match-1-must-be-a-posi","errorCode":null,"errorMessage":"Invalid size amount: '${match[1]}'. Must be a positive number.","messagePattern":"Invalid size amount: '(.+?)'\\. Must be a positive number\\.","errorType":"validation","errorClass":"RepomixError","httpStatus":null,"severity":"error","filePath":"src/shared/sizeParse.ts","lineNumber":15,"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;\n};\n","sourceCodeStart":1,"sourceCodeEnd":28,"githubUrl":"https://github.com/yamadashy/repomix/blob/f465ad909315a22120636baf03fa5e28701a50cb/src/shared/sizeParse.ts#L1-L28","documentation":"After the regex matches, the numeric portion is validated: it must be finite and > 0. This guard catches values the regex cannot express (e.g. '0mb' matches the regex but is not positive) or edge inputs where the captured amount is not a usable number, throwing a RepomixError.","triggerScenarios":"Passing '0kb', '0mb', or '0.0mb' to a size option — the format is valid but the amount is zero — or a number so huge it becomes Infinity at Number() conversion (extremely long digit strings).","commonSituations":"Users setting a 'minimum size' style option to 0 thinking it disables the limit, when a positive value is required instead.","solutions":["Use a strictly positive value, e.g. '0.1mb' instead of '0mb'","If you intended to disable the limit, omit the size option entirely rather than setting 0","Check for accidental digits-only-zero input like '0kb' from templated config"],"exampleFix":"// before\n{ \"output\": { \"truncateSize\": \"0mb\" } }\n// after\n// remove the option, or:\n{ \"output\": { \"truncateSize\": \"0.1mb\" } }","handlingStrategy":"validation","validationCode":"const m = /^\\s*(\\d+(?:\\.\\d+)?)\\s*(kb|mb)\\s*$/i.exec(raw);\nif (!m || !(Number(m[1]) > 0)) throw new Error(`'${raw}' must be a positive kb/mb amount`);","typeGuard":null,"tryCatchPattern":"try {\n  const bytes = parseHumanSizeToBytes(raw);\n} catch (e) {\n  if (String(e.message).startsWith('Invalid size amount')) {\n    // replace zero/non-positive amount with a positive value\n  } else throw e;\n}","preventionTips":["Never set size options to 0; omit them to disable limits","Guard templated config values with Number(v) > 0 checks"],"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"}