{"record":{"id":"9368373b22ec91c6","repo":"koala73/worldmonitor","slug":"unrecognised-argument-arg","errorCode":null,"errorMessage":"Unrecognised argument: ${arg}","messagePattern":"Unrecognised argument: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"scripts/merge-train.mjs","lineNumber":234,"sourceCode":"      await gh(['api', '--method', 'PUT', `repos/${repo}/pulls/${number}/update-branch`]);\n    },\n\n    async merge(number) {\n      await gh(['pr', 'merge', String(number), '--repo', repo, '--squash']);\n    },\n  };\n}\n\nexport function parseArgs(argv) {\n  const numbers = [];\n  let execute = false;\n  let file = null;\n  for (let index = 0; index < argv.length; index += 1) {\n    const arg = argv[index];\n    if (arg === '--execute') { execute = true; continue; }\n    if (arg === '--file') { file = argv[index + 1]; index += 1; continue; }\n    if (/^\\d+$/.test(arg)) { numbers.push(Number(arg)); continue; }\n    throw new Error(`Unrecognised argument: ${arg}`);\n  }\n  if (file) {\n    for (const line of readFileSync(file, 'utf8').split('\\n')) {\n      const match = line.trim().match(/^#?(\\d+)$/);\n      if (match) numbers.push(Number(match[1]));\n    }\n  }\n  if (numbers.length === 0) throw new Error('No PR numbers given');\n  return { queue: [...new Set(numbers)], execute };\n}\n\nconst USAGE = `usage: node scripts/merge-train.mjs <pr>... [--file <path>] [--execute]\n\nRe-evaluates the Deploy Gate for each PR's exact head immediately before\nmerging it, so no PR merges on a verdict that predates the previous merge.\nWithout --execute it only reports what it would do.`;\n\nif (isMainModule(import.meta.url, process.argv[1])) {","sourceCodeStart":216,"sourceCodeEnd":252,"githubUrl":"https://github.com/koala73/worldmonitor/blob/e586b8b4b80f595aa7ece295eec10d76f2921240/scripts/merge-train.mjs#L216-L252","documentation":"parseArgs() in merge-train.mjs accepts only --execute, --file <path>, and bare numeric PR numbers. Any other token throws 'Unrecognised argument: <arg>'. The strict allow-list prevents silently ignoring mistyped flags or accidental junk arguments.","triggerScenarios":"Running node scripts/merge-train.mjs --dry-run 123, passing a PR reference like #456 on the command line (the # prefix is only honored inside --file), or a mistyped flag such as --execut.","commonSituations":"Copy-pasting flags from other scripts, passing GitHub-style '#123' references, or including extra words from a usage example.","solutions":["Use only supported arguments: <pr numbers>, --file <path>, --execute","Strip the '#' from PR references on the command line (123 not #123)","Fix the flag spelling (e.g. --execute) or remove unsupported flags","Put multi-line PR lists in a file and pass it via --file"],"exampleFix":"// before\nnode scripts/merge-train.mjs #123 --dry-run\n// after\nnode scripts/merge-train.mjs 123","handlingStrategy":"validation","validationCode":"const KNOWN = ['--execute', '--file'];\nfor (const a of argv) {\n  if (!/^[\\d#]+$/.test(a) && !KNOWN.some(k => a === k || a.startsWith('--file'))) throw new Error(`Unrecognised argument: ${a}`);\n}","typeGuard":"null","tryCatchPattern":"try {\n  const { queue, execute } = parseArgs(process.argv.slice(2));\n} catch (err) {\n  if (err.message.startsWith('Unrecognised argument')) console.error(`${err.message}\\n${USAGE}`);\n  process.exit(2);\n}","preventionTips":["Pass only plain numeric PR numbers on the command line (123, not #123)","Use --file for list inputs and --execute to actually merge","Consult the USAGE string before constructing the command"],"tags":["cli","arguments","git"],"backgroundTag":"invalid-cli-argument","analyzedSha":"e586b8b4b80f595aa7ece295eec10d76f2921240","analyzedAt":"2026-09-22T01:50:49.965Z","contentChangedAt":"2026-09-22T01:50:49.965Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}