{"record":{"id":"c5e30c858a85000f","repo":"jackwener/OpenCLI","slug":"osv-label-cannot-be-empty","errorCode":null,"errorMessage":"osv ${label} cannot be empty","messagePattern":"osv (.+?) cannot be empty","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/osv/utils.js","lineNumber":36,"sourceCode":"    'PyPI',\n    'Go',\n    'Maven',\n    'NuGet',\n    'RubyGems',\n    'crates.io',\n    'Packagist',\n    'Pub',\n    'Hex',\n    'Hackage',\n    'CRAN',\n    'Bitnami',\n    'GitHub Actions',\n    'SwiftURL',\n]);\n\nexport function requireString(value, label) {\n    const s = String(value ?? '').trim();\n    if (!s) throw new ArgumentError(`osv ${label} cannot be empty`);\n    return s;\n}\n\nexport function requireVulnId(value) {\n    const s = String(value ?? '').trim();\n    if (!s) {\n        throw new ArgumentError(\n            'osv vulnerability id is required (e.g. \"GHSA-29mw-wpgm-hmr9\", \"CVE-2020-28500\")',\n            'IDs are listed at https://osv.dev — paste the canonical id from the vulnerability page.',\n        );\n    }\n    if (!VULN_ID.test(s)) {\n        throw new ArgumentError(\n            `osv vulnerability id \"${value}\" is not a valid OSV id`,\n            'IDs are short ASCII tokens like \"GHSA-...\", \"CVE-...\", \"PYSEC-...\".',\n        );\n    }\n    return s;","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/osv/utils.js#L18-L54","documentation":"requireString rejects any value that is null, undefined, or trims to an empty string for a required OSV CLI string argument. It throws ArgumentError before any network call is made.","triggerScenarios":"Calling a command that routes through requireString (e.g. package `name`) with an empty string, whitespace-only string, null, or undefined — commonly an unset flag or shell variable that expanded to nothing.","commonSituations":"`--name \"\"` on the command line; an env var like $PKG that is unset; a script passing an empty field from a parsed manifest; piping empty input.","solutions":["Supply the required argument, e.g. --name lodash.","Check that the shell variable feeding the flag is actually set and non-empty.","Quote arguments so whitespace doesn't get eaten, and trim user input before passing.","Add shell-level checks ([ -n \"$PKG\" ]) before invoking the command in scripts."],"exampleFix":"// before\nconst name = requireString(process.env.PKG, 'name'); // PKG unset\n// after\nconst name = requireString(process.env.PKG || 'lodash', 'name');","handlingStrategy":"validation","validationCode":"if (value == null || String(value).trim() === '') {\n  throw new Error(`osv ${label} cannot be empty: provide a non-empty value`);\n}","typeGuard":"const isNonEmptyString = (v) => typeof v === 'string' && v.trim().length > 0;","tryCatchPattern":"try {\n  return await runOsvCommand(args);\n} catch (e) {\n  if (e instanceof ArgumentError && /cannot be empty/.test(e.message)) {\n    console.error(`Missing required argument: ${e.message}`);\n    process.exitCode = 2;\n    return;\n  }\n  throw e;\n}","preventionTips":["Always quote CLI flags so empty expansions are visible.","Check env vars with [ -n \"$VAR\" ] in shell scripts before invoking.","Trim user/file input before passing to the CLI.","Use required-argument checks at the entry point of wrapper scripts."],"tags":["argument-validation","input-validation","osv"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}