{"record":{"id":"97d0211644d8df7c","repo":"yamadashy/repomix","slug":"invalid-maxbytesperpart-maxbytesperpart","errorCode":null,"errorMessage":"Invalid maxBytesPerPart: ${maxBytesPerPart}","messagePattern":"Invalid maxBytesPerPart: (.+?)","errorType":"validation","errorClass":"RepomixError","httpStatus":null,"severity":"error","filePath":"src/core/output/outputSplit.ts","lineNumber":195,"sourceCode":"  emptyDirPaths,\n  deps,\n}: {\n  rootDirs: string[];\n  baseConfig: RepomixConfigMerged;\n  processedFiles: ProcessedFile[];\n  allFilePaths: string[];\n  maxBytesPerPart: number;\n  gitDiffResult: GitDiffResult | undefined;\n  gitLogResult: GitLogResult | undefined;\n  progressCallback: RepomixProgressCallback;\n  filePathsByRoot?: FilesByRoot[];\n  emptyDirPaths?: string[];\n  deps: {\n    generateOutput: GenerateOutputFn;\n  };\n}): Promise<OutputSplitPart[]> => {\n  if (!Number.isSafeInteger(maxBytesPerPart) || maxBytesPerPart <= 0) {\n    throw new RepomixError(`Invalid maxBytesPerPart: ${maxBytesPerPart}`);\n  }\n\n  const groups = buildOutputSplitGroups(processedFiles, allFilePaths);\n  if (groups.length === 0) {\n    return [];\n  }\n\n  const parts: OutputSplitPart[] = [];\n  let currentGroups: OutputSplitGroup[] = [];\n  let currentContent = '';\n  let currentBytes = 0;\n\n  // Groups are processed via a queue so an oversized group can be replaced in place by its\n  // finer-grained subdivisions (see below) and re-evaluated without special-casing the loop.\n  const queue: OutputSplitGroup[] = [...groups];\n\n  const finalizeCurrentPart = () => {\n    parts.push({","sourceCodeStart":177,"sourceCodeEnd":213,"githubUrl":"https://github.com/yamadashy/repomix/blob/f465ad909315a22120636baf03fa5e28701a50cb/src/core/output/outputSplit.ts#L177-L213","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass a positive integer byte count, e.g. maxBytesPerPart: 50_000_000.","Parse user input with Number.parseInt and validate before calling.","Check the upstream calculation for NaN/Infinity (e.g. failed string parsing)."],"exampleFix":"// before\nconst maxBytes = Number.parseInt(argv['max-bytes-per-part']);\nawait generateSplitOutputParts({ maxBytesPerPart: maxBytes, ... });\n// after\nconst maxBytes = Number.parseInt(argv['max-bytes-per-part'], 10);\nif (!Number.isSafeInteger(maxBytes) || maxBytes <= 0) {\n  throw new Error('maxBytesPerPart must be a positive integer');\n}\nawait generateSplitOutputParts({ maxBytesPerPart: maxBytes, ... });","handlingStrategy":"validation","validationCode":"export const isValidMaxBytes = (n: unknown): n is number =>\n  typeof n === 'number' && Number.isSafeInteger(n) && n > 0;\nif (!isValidMaxBytes(maxBytesPerPart)) throw new Error('maxBytesPerPart must be a positive integer');","typeGuard":"const isPositiveSafeInt = (v: unknown): v is number =>\n  typeof v === 'number' && Number.isSafeInteger(v) && v > 0;","tryCatchPattern":"try {\n  await generateSplitOutputParts({ maxBytesPerPart, ... });\n} catch (e) {\n  if (e instanceof RepomixError && e.message.startsWith('Invalid maxBytesPerPart')) {\n    console.error('Supply a positive integer byte limit, e.g. 50000000');\n  } else throw e;\n}","preventionTips":["Always parse size options with Number.parseInt(value, 10).","Validate numeric CLI options at the argument-parsing layer.","Never compute the limit from unparsed strings like '50MB'."],"tags":["validation","arguments","output-split"],"backgroundTag":"invalid-argument","analyzedSha":"f465ad909315a22120636baf03fa5e28701a50cb","analyzedAt":"2026-08-29T01:27:42.024Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}