yamadashy/repomix · error · RepomixError

Invalid maxBytesPerPart: ${maxBytesPerPart}

Error message

Invalid maxBytesPerPart: ${maxBytesPerPart}

What it means

generateSplitOutputParts validates that `maxBytesPerPart` is a positive safe integer before splitting output into parts; any other value (0, negative, NaN, Infinity, fractional, or non-numeric) throws this RepomixError. It is an argument-contract guard protecting the split algorithm from nonsensical size limits.

Source

Thrown at src/core/output/outputSplit.ts:195

  emptyDirPaths,
  deps,
}: {
  rootDirs: string[];
  baseConfig: RepomixConfigMerged;
  processedFiles: ProcessedFile[];
  allFilePaths: string[];
  maxBytesPerPart: number;
  gitDiffResult: GitDiffResult | undefined;
  gitLogResult: GitLogResult | undefined;
  progressCallback: RepomixProgressCallback;
  filePathsByRoot?: FilesByRoot[];
  emptyDirPaths?: string[];
  deps: {
    generateOutput: GenerateOutputFn;
  };
}): Promise<OutputSplitPart[]> => {
  if (!Number.isSafeInteger(maxBytesPerPart) || maxBytesPerPart <= 0) {
    throw new RepomixError(`Invalid maxBytesPerPart: ${maxBytesPerPart}`);
  }

  const groups = buildOutputSplitGroups(processedFiles, allFilePaths);
  if (groups.length === 0) {
    return [];
  }

  const parts: OutputSplitPart[] = [];
  let currentGroups: OutputSplitGroup[] = [];
  let currentContent = '';
  let currentBytes = 0;

  // Groups are processed via a queue so an oversized group can be replaced in place by its
  // finer-grained subdivisions (see below) and re-evaluated without special-casing the loop.
  const queue: OutputSplitGroup[] = [...groups];

  const finalizeCurrentPart = () => {
    parts.push({

View on GitHub (pinned to f465ad9093)

Solutions

  1. Pass a positive integer byte count, e.g. maxBytesPerPart: 50_000_000.
  2. Parse user input with Number.parseInt and validate before calling.
  3. Check the upstream calculation for NaN/Infinity (e.g. failed string parsing).

Example fix

// before
const maxBytes = Number.parseInt(argv['max-bytes-per-part']);
await generateSplitOutputParts({ maxBytesPerPart: maxBytes, ... });
// after
const maxBytes = Number.parseInt(argv['max-bytes-per-part'], 10);
if (!Number.isSafeInteger(maxBytes) || maxBytes <= 0) {
  throw new Error('maxBytesPerPart must be a positive integer');
}
await generateSplitOutputParts({ maxBytesPerPart: maxBytes, ... });
Defensive patterns

Strategy: validation

Validate before calling

export const isValidMaxBytes = (n: unknown): n is number =>
  typeof n === 'number' && Number.isSafeInteger(n) && n > 0;
if (!isValidMaxBytes(maxBytesPerPart)) throw new Error('maxBytesPerPart must be a positive integer');

Type guard

const isPositiveSafeInt = (v: unknown): v is number =>
  typeof v === 'number' && Number.isSafeInteger(v) && v > 0;

Try / catch

try {
  await generateSplitOutputParts({ maxBytesPerPart, ... });
} catch (e) {
  if (e instanceof RepomixError && e.message.startsWith('Invalid maxBytesPerPart')) {
    console.error('Supply a positive integer byte limit, e.g. 50000000');
  } else throw e;
}

Prevention

When it happens

Trigger: Calling generateSplitOutputParts (or the split-output CLI/API path) with maxBytesPerPart computed from bad input: a parse of `--max-bytes-per-part` that yields NaN, an unset option defaulting to 0, or a float value.

Common situations: Passing `--output-split`-style sizing with an empty or malformed value; computing the limit from a byte-size string like "50MB" without parsing; copying example code but omitting the limit constant.

Related errors


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