{"record":{"id":"d1df7db4e736ab2e","repo":"jackwener/OpenCLI","slug":"rfc-number-is-required-e-g-9000-791-2616","errorCode":null,"errorMessage":"rfc number is required (e.g. 9000, 791, 2616)","messagePattern":"rfc number is required \\(e\\.g\\. 9000, 791, 2616\\)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/rfc/utils.js","lineNumber":14,"sourceCode":"// Shared helpers for the IETF RFC adapter.\n//\n// datatracker.ietf.org publishes a free, unauthenticated REST API. The\n// `/doc/<name>/doc.json` endpoint returns rich metadata for any IETF document\n// (RFCs, internet drafts, etc.). Docs: https://datatracker.ietf.org/api/\nimport { ArgumentError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';\n\nexport const RFC_BASE = 'https://datatracker.ietf.org';\nconst UA = 'opencli-rfc-adapter (+https://github.com/jackwener/opencli)';\n\nexport function requireRfcNumber(value) {\n    const raw = value;\n    if (raw == null || String(raw).trim() === '') {\n        throw new ArgumentError(\n            'rfc number is required (e.g. 9000, 791, 2616)',\n            'Pass the integer RFC number; do not include the \"rfc\" prefix.',\n        );\n    }\n    // Accept \"9000\" or 9000 or \"rfc9000\" as a courtesy.\n    const s = String(raw).trim().toLowerCase().replace(/^rfc/, '');\n    const n = Number.parseInt(s, 10);\n    if (!Number.isInteger(n) || n <= 0 || String(n) !== s) {\n        throw new ArgumentError(\n            `rfc number \"${value}\" is not a valid RFC number`,\n            'Pass a positive integer (e.g. 9000, 791, 2616).',\n        );\n    }\n    if (n > 999999) {\n        throw new ArgumentError('rfc number must be <= 999999');\n    }\n    return n;\n}","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/rfc/utils.js#L1-L32","documentation":"requireRfcNumber validates that an RFC number argument was actually provided. It throws ArgumentError when the value is null/undefined or an empty/whitespace-only string, with a hint that the 'rfc' prefix should not be included.","triggerScenarios":"Running `rfc rfc` without --number or with an empty value (--number '', --number ' '), or calling requireRfcNumber(null/undefined) programmatically.","commonSituations":"Forgetting the required argument in scripts, a variable that failed to interpolate leaving --number '' empty, or users typing 'rfc rfc rfc9000' expecting prefix parsing (prefix is accepted later, but emptiness is not).","solutions":["Provide the RFC number, e.g. --number 9000.","Ensure the shell variable holding the number is actually set and non-empty.","Pass the bare integer; the 'rfc' prefix is optional but a value is required.","Wrap the call in try/catch on ArgumentError to prompt the user for input."],"exampleFix":"// before\nrfc rfc --number \"\"\n// after\nrfc rfc --number 2616","handlingStrategy":"validation","validationCode":"function hasRfcNumber(v) {\n  return v != null && String(v).trim() !== '';\n}\nif (!hasRfcNumber(args.number)) throw new Error('usage: rfc rfc --number <int>');","typeGuard":"const isPresent = (v) => v !== undefined && v !== null && String(v).trim() !== '';","tryCatchPattern":"try {\n  const n = requireRfcNumber(args.number);\n} catch (err) {\n  if (err instanceof ArgumentError) {\n    console.error(err.message + '\\n' + (err.hint ?? ''));\n    process.exitCode = 2;\n  } else throw err;\n}","preventionTips":["Make the number a required positional arg so omission fails at parse time.","Check shell variables are set before interpolation (${N:?unset}).","Print usage text when the argument is missing.","Never pass empty strings as defaults for required numeric args."],"tags":["cli","missing-argument","argument-validation"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}