{"record":{"id":"f8a7db101d523e83","repo":"jackwener/OpenCLI","slug":"nuget-package-id-is-required-e-g-newtonsoft-jso","errorCode":null,"errorMessage":"nuget package id is required (e.g. \"Newtonsoft.Json\")","messagePattern":"nuget package id is required \\(e\\.g\\. \"Newtonsoft\\.Json\"\\)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/nuget/utils.js","lineNumber":38,"sourceCode":"    if (!s) throw new ArgumentError(`nuget ${label} cannot be empty`);\n    return s;\n}\n\nexport function requireBoundedInt(value, defaultValue, maxValue, label = 'limit') {\n    const raw = value ?? defaultValue;\n    const n = typeof raw === 'number' ? raw : Number(raw);\n    if (!Number.isInteger(n) || n <= 0) {\n        throw new ArgumentError(`nuget ${label} must be a positive integer`);\n    }\n    if (n > maxValue) {\n        throw new ArgumentError(`nuget ${label} must be <= ${maxValue}`);\n    }\n    return n;\n}\n\nexport function requirePackageId(value) {\n    const raw = String(value ?? '').trim();\n    if (!raw) throw new ArgumentError('nuget package id is required (e.g. \"Newtonsoft.Json\")');\n    if (!PACKAGE_ID_PATTERN.test(raw)) {\n        throw new ArgumentError(\n            `nuget package id \"${value}\" is not a valid NuGet identifier`,\n            'NuGet IDs are 1-100 chars: letters/digits/`.`/`_`/`-`, starting with letter or digit.',\n        );\n    }\n    return raw;\n}\n\nexport async function nugetFetch(url, label) {\n    let resp;\n    try {\n        resp = await fetch(url, { headers: { 'user-agent': UA, accept: 'application/json' } });\n    }\n    catch (err) {\n        throw new CommandExecutionError(\n            `${label} request failed: ${err?.message ?? err}`,\n            'Check that api.nuget.org is reachable from this network.',","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/nuget/utils.js#L20-L56","documentation":"This ArgumentError is thrown by requirePackageId in clis/nuget/utils.js when the package id option is empty, undefined, or only whitespace. The library requires an explicit NuGet package id for detail/registration lookups because there is no sensible default. It fails fast before any network request is made.","triggerScenarios":"Calling a nuget package-detail command with id undefined, null, '' or '   '; forgetting the positional/flag argument; a script variable expanding to empty.","commonSituations":"Copy-pasting a command and dropping the package name; CI pipelines where a version-matrix variable is unset; programmatic wrappers passing options without the required id key.","solutions":["Provide a package id, e.g. id: 'Newtonsoft.Json'","Check that the variable feeding the id is set and non-empty before the call","Use a search/leaf command instead if you do not yet know the exact package id"],"exampleFix":"// before\nawait nuget.info(ctx, { id: process.env.PKG }); // PKG unset\n// after\nawait nuget.info(ctx, { id: process.env.PKG || 'Newtonsoft.Json' });","handlingStrategy":"validation","validationCode":"if (!opts.id || !String(opts.id).trim()) throw new Error('nvd/nuget: package id is required');","typeGuard":"function hasPackageId(o) { return typeof o?.id === 'string' && o.id.trim().length > 0; }","tryCatchPattern":"try {\n  await nuget.info(ctx, { id });\n} catch (e) {\n  if (e instanceof ArgumentError && e.message.includes('package id is required')) {\n    console.error('Usage: pass --id <PackageId>');\n  } else throw e;\n}","preventionTips":["Validate required options at your CLI/parser boundary","Check for unset env variables feeding the id before invoking","Fail early in scripts with a clear usage message","Use the search command when the exact id is unknown"],"tags":["validation","arguments","required-field","nuget"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}