jackwener/OpenCLI · error · ArgumentError

nuget package id is required (e.g. "Newtonsoft.Json")

Error message

nuget package id is required (e.g. "Newtonsoft.Json")

What it means

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.

Source

Thrown at clis/nuget/utils.js:38

    if (!s) throw new ArgumentError(`nuget ${label} cannot be empty`);
    return s;
}

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

  1. Provide a package id, e.g. id: 'Newtonsoft.Json'
  2. Check that the variable feeding the id is set and non-empty before the call
  3. Use a search/leaf command instead if you do not yet know the exact package id

Example fix

// before
await nuget.info(ctx, { id: process.env.PKG }); // PKG unset
// after
await nuget.info(ctx, { id: process.env.PKG || 'Newtonsoft.Json' });
Defensive patterns

Strategy: validation

Validate before calling

if (!opts.id || !String(opts.id).trim()) throw new Error('nvd/nuget: package id is required');

Type guard

function hasPackageId(o) { return typeof o?.id === 'string' && o.id.trim().length > 0; }

Try / catch

try {
  await nuget.info(ctx, { id });
} catch (e) {
  if (e instanceof ArgumentError && e.message.includes('package id is required')) {
    console.error('Usage: pass --id <PackageId>');
  } else throw e;
}

Prevention

When it happens

Trigger: Calling a nuget package-detail command with id undefined, null, '' or ' '; forgetting the positional/flag argument; a script variable expanding to empty.

Common situations: 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.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/f8a7db101d523e83. Report an issue: GitHub.