{"record":{"id":"ca56cde175d79a20","repo":"affaan-m/ECC","slug":"invalid-issue-number-value","errorCode":null,"errorMessage":"Invalid issue number: ${value}","messagePattern":"Invalid issue number: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"scripts/lib/github-coordination/gh-api.js","lineNumber":17,"sourceCode":"'use strict';\n\nconst { spawnSync } = require('child_process');\n\nfunction normalizeRepo(repo) {\n  const parts = String(repo || '').split('/').filter(Boolean);\n  if (parts.length !== 2) {\n    throw new Error(`Invalid repo format: \"${repo}\". Expected \"owner/repo\".`);\n  }\n  const [owner, name] = parts;\n  return { owner, name };\n}\n\nfunction normalizeIssueNumber(value) {\n  const parsed = Number.parseInt(String(value), 10);\n  if (!Number.isFinite(parsed) || parsed <= 0) {\n    throw new Error(`Invalid issue number: ${value}`);\n  }\n  return parsed;\n}\n\nfunction normalizeLabelValue(label) {\n  if (typeof label === 'string') {\n    return label.trim();\n  }\n  if (label && typeof label === 'object') {\n    return String(label.name || label.label || '').trim();\n  }\n  return '';\n}\n\nfunction normalizeLabels(labels) {\n  return Array.from(new Set((Array.isArray(labels) ? labels : []).map(normalizeLabelValue).filter(Boolean))).sort();\n}\n","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/scripts/lib/github-coordination/gh-api.js#L1-L35","documentation":"normalizeIssueNumber validates that a value can be parsed as a positive integer issue number before any gh API call is made. It throws when the value is not an integer or is <= 0, because GitHub issue numbers are strictly positive integers. This is an early input-validation guard so malformed numbers fail fast instead of producing a confusing gh CLI error.","triggerScenarios":"Calling getIssue/issue/applyClaim (via VALUE_FLAGS or parseArgs) with a non-numeric string like 'abc', a float like '12.5', a zero or negative number like '0' or '-3', or an empty/undefined value passed as the issue identifier.","commonSituations":"Users pass a branch name or PR URL fragment instead of a number, scripts interpolate an unset shell variable producing an empty string, users pass a GitHub URL (#123 or full URL) rather than the bare number, or a parsed value includes trailing whitespace/characters like '123, '.","solutions":["Pass the bare positive integer issue number, e.g. 123 not '#123' or a URL.","Strip prefixes and whitespace before calling: Number.parseInt(value.replace('#','').trim(), 10).","Check that the variable holding the number is actually set in your shell/script before invoking the command.","If deriving the number from a URL, extract the final numeric path segment first."],"exampleFix":"// before\nnode script.js issue --issue \"$ISSUE_URL\"\n// after\nconst num = Number.parseInt(ISSUE_URL.split('/').pop().replace('#', ''), 10);\nif (Number.isFinite(num) && num > 0) node script.js issue --issue num;","handlingStrategy":"validation","validationCode":"function isValidIssueNumber(v) {\n  const n = Number.parseInt(String(v).trim().replace(/^#/, ''), 10);\n  return Number.isFinite(n) && n > 0;\n}\nif (!isValidIssueNumber(input)) throw new Error(`Bad issue number: ${input}`);","typeGuard":"const isPositiveInt = (v) => Number.isFinite(Number.parseInt(String(v), 10)) && Number.parseInt(String(v), 10) > 0;","tryCatchPattern":"let num;\ntry {\n  num = normalizeIssueNumber(raw);\n} catch (e) {\n  if (e.message.startsWith('Invalid issue number')) {\n    console.error(`Please pass a positive integer, got: ${raw}`);\n    process.exitCode = 1;\n    return;\n  }\n  throw e;\n}","preventionTips":["Always pass bare integers, not '#123' or URLs.","Strip '#' and whitespace before parsing.","Validate shell variables are non-empty before interpolation.","Centralize issue-number parsing in one helper used by all scripts."],"tags":["input-validation","cli","github-issues"],"backgroundTag":"invalid-argument-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"}