{"record":{"id":"252c885ad4b0b487","repo":"vercel/next.js","slug":"invalid-top-value-topraw","errorCode":null,"errorMessage":"Invalid --top value: ${topRaw}","messagePattern":"Invalid --top value: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"bench/render-pipeline/analyze-profiles.ts","lineNumber":74,"sourceCode":"\nfunction parseArgs() {\n  const rawArgs = process.argv.slice(2)\n  if (rawArgs.includes('--help')) {\n    usage()\n    process.exit(0)\n  }\n\n  const args = new Map<string, string>()\n  for (const rawArg of rawArgs) {\n    if (!rawArg.startsWith('--')) continue\n    const [rawKey, rawValue] = rawArg.slice(2).split('=')\n    args.set(rawKey, rawValue ?? 'true')\n  }\n\n  const topRaw = args.get('top')\n  const top = topRaw ? Number(topRaw) : 15\n  if (!Number.isFinite(top) || top < 1) {\n    throw new Error(`Invalid --top value: ${topRaw}`)\n  }\n\n  return {\n    artifactDirArg: args.get('artifact-dir'),\n    top: Math.floor(top),\n  }\n}\n\nasync function exists(path: string): Promise<boolean> {\n  try {\n    await access(path, constants.F_OK)\n    return true\n  } catch {\n    return false\n  }\n}\n\nasync function resolveArtifactRunDir(artifactDirArg?: string): Promise<string> {","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/vercel/next.js/blob/0ae8c72462952df163f1b1e0726641bc5b40dc93/bench/render-pipeline/analyze-profiles.ts#L56-L92","documentation":"Thrown by parseArgs (analyze-profiles.ts:74) when the --top value, after Number(), is not finite or is less than 1. The value controls how many hotspots are printed per section (modules, runtime sources, runtime symbols) and is floored to an integer afterward, so zero/negative/non-numeric is rejected as meaningless. Default is 15 when --top is omitted.","triggerScenarios":"Running `pnpm bench:render-pipeline:analyze --top=<x>` with x being non-numeric (abc, empty after =), Infinity-ish (e.g. a bare --top with no value yields 'true' -> NaN), zero, or negative. Number('') is 0 and fails the < 1 check; Number('true') is NaN and fails !isFinite.","commonSituations":"Passing --top with no value (--top instead of --top=15, which makes rawValue undefined -> 'true' -> NaN); passing 0 expecting 'show all' (the script has no 'all' sentinel); a wrapper script forwarding an unbound variable.","solutions":["Pass a positive integer: --top=15 (default) or any N >= 1.","If you used a bare --top, add =N; bare flags resolve to 'true' here.","There is intentionally no 'unlimited' option; pick a large N (e.g. 100) instead of 0.","Wrap the value through a numeric check in calling scripts before invoking analyze."],"exampleFix":"// before\n//   pnpm bench:render-pipeline:analyze --top=0\n//   pnpm bench:render-pipeline:analyze --top\n\n// after\n//   pnpm bench:render-pipeline:analyze --top=30","handlingStrategy":"validation","validationCode":"function parseTop(raw: string | undefined): number {\n  const n = raw ? Number(raw) : 15\n  if (!Number.isInteger(n) || n < 1) {\n    throw new Error(`--top must be a positive integer (got ${raw ?? 'unset'})`)\n  }\n  return n\n}","typeGuard":"function isPositiveIntegerString(s: string): boolean {\n  const n = Number(s)\n  return Number.isInteger(n) && n >= 1\n}","tryCatchPattern":"// CLI validation failure is fatal and clear; typically don't catch. If scripting:\ntry {\n  parseArgs()\n} catch (err) {\n  console.error((err as Error).message, '\\nUsage: --top=<positive integer>')\n  process.exit(2)\n}","preventionTips":["Always pass --top with a value: --top=15, never a bare --top.","There is no 'unlimited'; choose a large finite N.","Validate templated values in wrapper scripts before invoking analyze.","Remember the default is 15 — usually you can omit the flag."],"tags":["cli","argument-parsing","analyze-profiles","validation","numeric"],"analyzedSha":"0ae8c72462952df163f1b1e0726641bc5b40dc93","analyzedAt":"2026-08-06T19:44:29.143Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}