{"record":{"id":"66d46124ac56d874","repo":"affaan-m/ECC","slug":"invalid-flagname-value-66d461","errorCode":null,"errorMessage":"Invalid ${flagName}: ${value}","messagePattern":"Invalid (.+?): (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"scripts/platform-audit.js","lineNumber":61,"sourceCode":"    '  --allow-untracked <path>   Ignore untracked files under path; repeatable',\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    allowUntracked: [],\n    exitCode: false,\n    format: 'text',\n    help: false,\n    repos: [],\n    root: path.resolve(process.cwd()),\n    skipGithub: false,\n    thresholds: { ...DEFAULT_THRESHOLDS },\n    useEnvGithubToken: false,\n    writePath: null,\n  };","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/scripts/platform-audit.js#L43-L79","documentation":"parseIntegerFlag parses numeric CLI values for platform-audit (e.g. limits, page sizes). It uses Number.parseInt in base 10 and rejects the result if it is not a finite number or is negative, throwing `Invalid <flagName>: <value>`. Note parseInt is lenient about trailing garbage ('10abc' parses as 10), so the error fires mainly for non-numeric or negative input.","triggerScenarios":"Passing a non-numeric value (`--limit ten`), a negative number (`--limit -1`), a decimal that parseInt truncates is accepted but a pure non-numeric string is not, or an empty/unset shell variable so the value is '' (NaN).","commonSituations":"Copy-pasting values with units ('500ms', '5k') instead of bare integers; locale-formatted numbers with thousands separators ('1,000'); misremembering flag semantics and passing a negative 'offset from end'; an env var defaulting to empty string and becoming NaN.","solutions":["Provide a plain non-negative base-10 integer: `--limit 50`.","Strip units/separators: use 1000 not '1,000', 30 not '30s'.","If you need 'all', check whether the flag accepts 0 or a large sentinel rather than a negative number.","Validate in wrappers: `[[ $LIMIT =~ ^[0-9]+$ ]] || { echo \"bad limit\"; exit 1; }` before invoking."],"exampleFix":"// before\nargs.push('--limit', process.env.AUDIT_LIMIT); // '' -> NaN\n\n// after\nconst limit = Number.parseInt(process.env.AUDIT_LIMIT ?? '', 10);\nif (!Number.isFinite(limit) || limit < 0) {\n  throw new Error(`AUDIT_LIMIT must be a non-negative integer, got \"${process.env.AUDIT_LIMIT}\"`);\n}\nargs.push('--limit', String(limit));","handlingStrategy":"validation","validationCode":"const isNonNegativeInt = (v) => /^\\d+$/.test(String(v));\nif (!isNonNegativeInt(limit)) throw new Error(`limit must be a non-negative integer, got \"${limit}\"`);","typeGuard":"const isNonNegativeInt = (v) => typeof v === 'string' && /^\\d+$/.test(v) && Number.isSafeInteger(Number(v));","tryCatchPattern":"try {\n  const parsed = parseArgs(process.argv);\n} catch (err) {\n  if (/^Invalid /.test(err.message)) {\n    console.error(`${err.message} — numeric flags take plain non-negative integers (e.g. --limit 50)`);\n    process.exit(2);\n  }\n  throw err;\n}","preventionTips":["Pass bare integers: no units, separators, or signs.","Normalize external values (strip 'ms'/'k', commas) before passing.","Prefer strict regex validation over Number.parseInt in your own wrappers since parseInt accepts trailing garbage.","Document default values so users don't guess sentinel formats like -1 for 'unlimited'."],"tags":["cli","argument-parsing","validation","platform-audit"],"backgroundTag":"invalid-flag-value","analyzedSha":"8321021c54d670126ce3b2969d5deb880b4b0c2a","analyzedAt":"2026-09-16T10:08:13.343Z","contentChangedAt":"2026-09-16T10:08:13.343Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}