{"record":{"id":"2098cd3b5700ce30","repo":"jackwener/OpenCLI","slug":"nuget-package-id-value-is-not-a-valid-nuget-i","errorCode":null,"errorMessage":"nuget package id \"${value}\" is not a valid NuGet identifier","messagePattern":"nuget package id \"(.+?)\" is not a valid NuGet identifier","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/nuget/utils.js","lineNumber":40,"sourceCode":"}\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.',\n        );\n    }","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/nuget/utils.js#L22-L58","documentation":"This ArgumentError is thrown by requirePackageId in clis/nuget/utils.js when the package id is non-empty but does not match the NuGet ID grammar enforced by PACKAGE_ID_PATTERN: 1-100 characters of letters/digits/`.`/`_`/`-`, starting with a letter or digit. The library validates the id client-side to avoid pointless 404s against the registration endpoint, since such ids can never exist on NuGet.","triggerScenarios":"Passing an id containing spaces, slashes ('Newtonsoft/Json'), '>=1.0.0' version-range syntax, a leading '.', '@scope/name' npm-style ids, an empty-after-trim value that still had odd characters, or an id longer than 100 chars.","commonSituations":"Mistakenly passing a package *version* or version range as the id; using npm/PyPI naming conventions on NuGet; copying a URL path fragment including 'packages/' or query strings; accidentally including surrounding quotes from a shell command.","solutions":["Use the exact NuGet package id, e.g. 'Newtonsoft.Json' or 'Microsoft.Extensions.Logging.Abstractions'","Strip URL prefixes/quotes/whitespace: pass only the id path segment","Move version constraints to the version option instead of embedding them in the id","Verify the id exists on nuget.org and copy it verbatim"],"exampleFix":"// before\nawait nuget.info(ctx, { id: 'Newtonsoft.Json >= 13.0.1' });\n// after\nawait nuget.info(ctx, { id: 'Newtonsoft.Json', version: '13.0.1' });","handlingStrategy":"validation","validationCode":"const PACKAGE_ID_PATTERN = /^[A-Za-z0-9](?:[A-Za-z0-9._-]{0,99})$/;\nif (!PACKAGE_ID_PATTERN.test(id)) throw new Error(`invalid NuGet id: ${id}`);","typeGuard":"function isValidNugetId(v) { return typeof v === 'string' && /^[A-Za-z0-9](?:[A-Za-z0-9._-]{0,99})$/.test(v); }","tryCatchPattern":"try {\n  await nuget.info(ctx, { id });\n} catch (e) {\n  if (e instanceof ArgumentError && e.message.includes('not a valid NuGet identifier')) {\n    console.error('IDs are 1-100 chars: alnum/./_/-, starting alnum');\n  } else throw e;\n}","preventionTips":["Strip URL prefixes, quotes, and whitespace before passing ids","Keep version strings out of the id; use the version option","Don't use npm @scope/name or PyPI naming on NuGet","Validate ids with the same regex the library uses"],"tags":["validation","arguments","regex","nuget"],"backgroundTag":"invalid-identifier-format","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}