yamadashy/repomix · error · RepomixError

Invalid size amount: '${match[1]}'. Must be a positive numbe

Error message

Invalid size amount: '${match[1]}'. Must be a positive number.

What it means

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.

Source

Thrown at src/shared/sizeParse.ts:15

import { RepomixError } from './errorHandle.js';

const SIZE_RE = /^\s*(\d+(?:\.\d+)?)\s*(kb|mb)\s*$/i;

export const parseHumanSizeToBytes = (input: string): number => {
  const match = SIZE_RE.exec(input);
  if (!match) {
    throw new RepomixError(
      `Invalid size: '${input}'. Expected format like '500kb', '2mb', or '2.5mb' (case-insensitive).`,
    );
  }

  const amount = Number(match[1]);
  if (!Number.isFinite(amount) || amount <= 0) {
    throw new RepomixError(`Invalid size amount: '${match[1]}'. Must be a positive number.`);
  }

  const unit = match[2].toLowerCase();
  const multiplier = unit === 'kb' ? 1024 : 1024 * 1024;
  const bytes = Math.floor(amount * multiplier);

  if (!Number.isSafeInteger(bytes)) {
    throw new RepomixError(`Invalid size: '${input}'. Resulting byte value is too large.`);
  }

  return bytes;
};

View on GitHub (pinned to f465ad9093)

Solutions

  1. Use a strictly positive value, e.g. '0.1mb' instead of '0mb'
  2. If you intended to disable the limit, omit the size option entirely rather than setting 0
  3. Check for accidental digits-only-zero input like '0kb' from templated config

Example fix

// before
{ "output": { "truncateSize": "0mb" } }
// after
// remove the option, or:
{ "output": { "truncateSize": "0.1mb" } }
Defensive patterns

Strategy: validation

Validate before calling

const m = /^\s*(\d+(?:\.\d+)?)\s*(kb|mb)\s*$/i.exec(raw);
if (!m || !(Number(m[1]) > 0)) throw new Error(`'${raw}' must be a positive kb/mb amount`);

Try / catch

try {
  const bytes = parseHumanSizeToBytes(raw);
} catch (e) {
  if (String(e.message).startsWith('Invalid size amount')) {
    // replace zero/non-positive amount with a positive value
  } else throw e;
}

Prevention

When it happens

Trigger: 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).

Common situations: Users setting a 'minimum size' style option to 0 thinking it disables the limit, when a positive value is required instead.

Related errors


AI-assisted analysis of yamadashy/repomix@f465ad9093 (2026-08-29). Data as JSON: /api/errors/f1a6092a19714921. Report an issue: GitHub.