{"record":{"id":"c12046ecd06092f4","repo":"badges/shields","slug":"error-processing-arguments","errorCode":null,"errorMessage":"Error processing arguments","messagePattern":"Error processing arguments","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/service-test-runner/pull-request-services-cli.js","lineNumber":22,"sourceCode":"// Output the list of services.\n//\n// Pull request title: [travis sonar] Support user token authentication\n//\n// Output:\n// travis\n// sonar\n\nimport servicesForTitle from './services-for-title.js'\n\nlet title\n\ntry {\n  if (process.argv.length < 3) {\n    throw new Error()\n  }\n  title = process.argv[2]\n} catch (e) {\n  console.error('Error processing arguments')\n  process.exit(1)\n}\n\nconsole.error(`Title: ${title}\\n`)\nconst services = servicesForTitle(title)\nif (services.length === 0) {\n  console.error('No services found. Nothing to do.')\n} else {\n  console.error(`Services: (${services.length} found) ${services.join(', ')}\\n`)\n  console.log(services.join('\\n'))\n}\n","sourceCodeStart":4,"sourceCodeEnd":34,"githubUrl":"https://github.com/badges/shields/blob/766fd8bc89a90b8534dc573ab72dec30215ab1ec/core/service-test-runner/pull-request-services-cli.js#L4-L34","documentation":"pull-request-services-cli.js is a small CLI that lists the services matching a PR title. It reads the title from process.argv[2]; if fewer than 3 argv entries are present it throws a bare Error caught locally, prints 'Error processing arguments' to stderr and exits with code 1. It is a usage error, not a library exception class.","triggerScenarios":"Running the script without a title argument, e.g. `node pull-request-services-cli.js` — process.argv.length < 3 so the guard throws.","commonSituations":"Forgetting to quote a title containing spaces so the shell splits it, invoking via a wrapper that drops arguments, running the wrong file expecting a different CLI signature.","solutions":["Pass the PR title as the first argument: `node pull-request-services-cli.js \"[docker] add foo service\"`.","Quote arguments containing spaces.","Check the script's usage/header comments for the expected argument order.","If wrapping the script, forward \"$@\" so arguments pass through."],"exampleFix":"// before\nnode core/service-test-runner/pull-request-services-cli.js\n// Error processing arguments (exit 1)\n// after\nnode core/service-test-runner/pull-request-services-cli.js \"[docker] add foo service\"","handlingStrategy":"validation","validationCode":"if (process.argv.length < 3) { console.error('Usage: node pull-request-services-cli.js \"<PR title>\"'); process.exit(1) }","typeGuard":"const hasTitleArg = args => Array.isArray(args) && typeof args[2] === 'string' && args[2].length > 0","tryCatchPattern":"try {\n  main(process.argv.slice(2))\n} catch (e) {\n  console.error('Error processing arguments:', e.message)\n  process.exit(1)\n}","preventionTips":["Always pass the PR title as the first quoted argument.","Quote titles containing spaces or brackets.","Check usage docs before invoking maintenance CLIs.","In wrappers, forward \"$@\" to preserve arguments."],"tags":["cli","arguments","usage","node"],"backgroundTag":"missing-cli-argument","analyzedSha":"766fd8bc89a90b8534dc573ab72dec30215ab1ec","analyzedAt":"2026-08-30T01:40:27.499Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}