{"record":{"id":"35b2268ee560f39a","repo":"jackwener/OpenCLI","slug":"nvd-cve-id-is-required-e-g-cve-2021-44228","errorCode":null,"errorMessage":"nvd CVE id is required (e.g. \"CVE-2021-44228\")","messagePattern":"nvd CVE id is required \\(e\\.g\\. \"CVE-2021-44228\"\\)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/nvd/cve.js","lineNumber":16,"sourceCode":"// nvd cve — fetch a single CVE from the NIST National Vulnerability Database.\n//\n// Hits the CVE API 2.0 (`services.nvd.nist.gov/rest/json/cves/2.0?cveId=…`).\n// Returns the agent-useful projection: id, published / last-modified dates,\n// vuln status, English description, CVSS v3.1 base score / severity / vector,\n// CWE id(s), CISA KEV flag.\nimport { cli, Strategy } from '@jackwener/opencli/registry';\nimport { ArgumentError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';\n\nconst NVD_BASE = 'https://services.nvd.nist.gov/rest/json/cves/2.0';\nconst UA = 'opencli-nvd-adapter (+https://github.com/jackwener/opencli)';\nconst CVE_ID = /^CVE-\\d{4}-\\d{4,}$/i;\n\nfunction requireCveId(value) {\n    const s = String(value ?? '').trim().toUpperCase();\n    if (!s) throw new ArgumentError('nvd CVE id is required (e.g. \"CVE-2021-44228\")');\n    if (!CVE_ID.test(s)) {\n        throw new ArgumentError(\n            `nvd CVE id \"${value}\" is not a valid CVE identifier`,\n            'Expected the form \"CVE-YYYY-N...\" with at least 4 sequence digits.',\n        );\n    }\n    return s;\n}\n\nfunction pickEnglishDescription(descriptions) {\n    if (!Array.isArray(descriptions)) return '';\n    const en = descriptions.find((d) => d?.lang === 'en');\n    return String(en?.value ?? descriptions[0]?.value ?? '').trim();\n}\n\nfunction pickPrimaryCvss(metrics) {\n    if (!metrics || typeof metrics !== 'object') return null;\n    const candidates = [","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/nvd/cve.js#L1-L34","documentation":"This ArgumentError is thrown by requireCveId in clis/nvd/cve.js when the CVE id argument is empty, undefined, or only whitespace. Looking up a CVE in the NVD API requires the id, and the library validates its presence client-side before making any request. The message shows the expected format.","triggerScenarios":"Calling the nvd cve id lookup with no argument, an empty string, or a variable that is unset/null in a script or CI job.","commonSituations":"Forgetting the positional CVE argument on the CLI; environment variables or spreadsheet columns that are blank; automation pipelines where an upstream step failed to produce a CVE id.","solutions":["Supply a CVE id, e.g. nvd cve CVE-2021-44228","Check that the variable feeding the id is set and non-empty","If you only have keywords, use the NVD keyword/search command instead of id lookup"],"exampleFix":"// before\nawait nvd.cve(ctx, { id: process.env.CVE }); // CVE unset\n// after\nawait nvd.cve(ctx, { id: process.env.CVE || 'CVE-2021-44228' });","handlingStrategy":"validation","validationCode":"const CVE_ID = /^CVE-\\d{4}-\\d{4,}$/i;\nif (!id || !CVE_ID.test(String(id).trim())) throw new Error('CVE id is required, e.g. CVE-2021-44228');","typeGuard":"function isValidCveId(v) { return typeof v === 'string' && /^CVE-\\d{4}-\\d{4,}$/i.test(v.trim()); }","tryCatchPattern":"try {\n  await nvd.cve(ctx, { id });\n} catch (e) {\n  if (e instanceof ArgumentError && e.message.includes('CVE id is required')) {\n    console.error('Usage: pass --id CVE-YYYY-NNNN');\n  } else throw e;\n}","preventionTips":["Validate CVE ids match /^CVE-\\d{4}-\\d{4,}$/i before calling","Check for unset/blank variables in scripts feeding the id","Use keyword search when you don't have an exact CVE id","Normalize casing (upper-case CVE prefix) before passing"],"tags":["validation","arguments","required-field","nvd","security"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}