jackwener/OpenCLI · error · ArgumentError
nuget package id "${value}" is not a valid NuGet identifier
Error message
nuget package id "${value}" is not a valid NuGet identifier What it means
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.
Source
Thrown at clis/nuget/utils.js:40
}
export function requireBoundedInt(value, defaultValue, maxValue, label = 'limit') {
const raw = value ?? defaultValue;
const n = typeof raw === 'number' ? raw : Number(raw);
if (!Number.isInteger(n) || n <= 0) {
throw new ArgumentError(`nuget ${label} must be a positive integer`);
}
if (n > maxValue) {
throw new ArgumentError(`nuget ${label} must be <= ${maxValue}`);
}
return n;
}
export function requirePackageId(value) {
const raw = String(value ?? '').trim();
if (!raw) throw new ArgumentError('nuget package id is required (e.g. "Newtonsoft.Json")');
if (!PACKAGE_ID_PATTERN.test(raw)) {
throw new ArgumentError(
`nuget package id "${value}" is not a valid NuGet identifier`,
'NuGet IDs are 1-100 chars: letters/digits/`.`/`_`/`-`, starting with letter or digit.',
);
}
return raw;
}
export async function nugetFetch(url, label) {
let resp;
try {
resp = await fetch(url, { headers: { 'user-agent': UA, accept: 'application/json' } });
}
catch (err) {
throw new CommandExecutionError(
`${label} request failed: ${err?.message ?? err}`,
'Check that api.nuget.org is reachable from this network.',
);
}View on GitHub (pinned to 49907e53dc)
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
Example fix
// before
await nuget.info(ctx, { id: 'Newtonsoft.Json >= 13.0.1' });
// after
await nuget.info(ctx, { id: 'Newtonsoft.Json', version: '13.0.1' }); Defensive patterns
Strategy: validation
Validate before calling
const PACKAGE_ID_PATTERN = /^[A-Za-z0-9](?:[A-Za-z0-9._-]{0,99})$/;
if (!PACKAGE_ID_PATTERN.test(id)) throw new Error(`invalid NuGet id: ${id}`); Type guard
function isValidNugetId(v) { return typeof v === 'string' && /^[A-Za-z0-9](?:[A-Za-z0-9._-]{0,99})$/.test(v); } Try / catch
try {
await nuget.info(ctx, { id });
} catch (e) {
if (e instanceof ArgumentError && e.message.includes('not a valid NuGet identifier')) {
console.error('IDs are 1-100 chars: alnum/./_/-, starting alnum');
} else throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- nuget ${label} must be a positive integer
- nuget ${label} must be <= ${maxValue}
- nuget package id is required (e.g. "Newtonsoft.Json")
- ${label} is required
- ${label} must be a positive integer
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/2098cd3b5700ce30.
Report an issue: GitHub.