{"record":{"id":"039b974ad322f20a","repo":"affaan-m/ECC","slug":"invalid-flagname-value","errorCode":null,"errorMessage":"Invalid ${flagName}: ${value}","messagePattern":"Invalid (.+?): (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/discussion-audit.js","lineNumber":52,"sourceCode":"    '  --first <n>                Discussions to sample per repo (default: 100)',\n    '  --use-env-github-token     Keep GITHUB_TOKEN when invoking gh',\n    '  --exit-code                Return 2 when the audit is not ready',\n    '  --help, -h                 Show this help',\n  ].join('\\n'));\n}\n\nfunction readValue(args, index, flagName) {\n  const value = args[index + 1];\n  if (!value || value.startsWith('--')) {\n    throw new Error(`${flagName} requires a value`);\n  }\n  return value;\n}\n\nfunction parseIntegerFlag(value, flagName) {\n  const parsed = Number.parseInt(value, 10);\n  if (!Number.isFinite(parsed) || parsed <= 0) {\n    throw new Error(`Invalid ${flagName}: ${value}`);\n  }\n  return parsed;\n}\n\nfunction parseArgs(argv) {\n  const args = argv.slice(2);\n  const parsed = {\n    exitCode: false,\n    first: DEFAULT_DISCUSSION_FIRST,\n    format: 'text',\n    help: false,\n    repos: [],\n    useEnvGithubToken: false,\n    writePath: null,\n  };\n\n  for (let index = 0; index < args.length; index += 1) {\n    const arg = args[index];","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/affaan-m/ECC/blob/01e15490f04e29cfefe3896951f43db46994d8ee/scripts/discussion-audit.js#L34-L70","documentation":"The parseIntegerFlag() function in discussion-audit.js uses Number.parseInt() and validates that the result is finite and greater than zero. This is used for the --first flag (number of discussions to sample per repo). Values like 0, negative numbers, NaN (from non-numeric strings), Infinity, or floats truncated to zero by parseInt all fail.","triggerScenarios":"Passing --first 0 (no discussions sampled), --first -10 (negative), --first abc (non-numeric), or --first 0.5 (parseInt returns 0). Note that parseInt('3.7') returns 3, which would pass — only values that parse to zero or NaN fail.","commonSituations":"Scripts deriving --first from a variable or calculation that can produce 0; passing a float that truncates to 0; environment-driven configuration with an unset variable defaulting to 0.","solutions":["Provide a positive integer, e.g. --first 100","If deriving from a variable, validate it is >= 1 before passing","Omit --first to use the default (DEFAULT_DISCUSSION_FIRST)"],"exampleFix":"// before\nnode scripts/discussion-audit.js --first 0\nnode scripts/discussion-audit.js --first abc\n// after\nnode scripts/discussion-audit.js --first 50","handlingStrategy":"validation","validationCode":"// Validate the --first value before passing it\nfunction isValidPositiveInteger(value) {\n  const n = Number.parseInt(value, 10);\n  return Number.isFinite(n) && n > 0;\n}\nconst first = process.env.AUDIT_FIRST || '100';\nif (!isValidPositiveInteger(first)) {\n  console.error(`Invalid --first value: ${first}. Must be a positive integer.`);\n  process.exit(1);\n}","typeGuard":"// Type guard for a positive integer\nfunction isPositiveInteger(value) {\n  const n = Number.parseInt(value, 10);\n  return Number.isFinite(n) && n > 0 && String(n) === String(value);\n}","tryCatchPattern":"try {\n  const options = parseArgs(process.argv);\n} catch (error) {\n  if (error.message.startsWith('Invalid') && error.message.includes(':')) {\n    console.error(error.message);\n    console.error('The --first flag requires a positive integer, e.g. --first 100');\n    process.exit(2);\n  }\n  throw error;\n}","preventionTips":["Pass a positive integer to --first (e.g. 50 or 100)","Omit --first to use the default sample count","When deriving from a variable, validate it is a positive integer before use"],"tags":["cli","argument-parsing","validation","discussion-audit"],"backgroundTag":null,"analyzedSha":"01e15490f04e29cfefe3896951f43db46994d8ee","analyzedAt":"2026-08-13T00:31:08.655Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}