jackwener/OpenCLI · error · ArgumentError

packagist package name is required (e.g. "symfony/console",

Error message

packagist package name is required (e.g. "symfony/console", "monolog/monolog")

What it means

requirePackageName throws this ArgumentError when, after trimming and lowercasing, the supplied package name is empty (or contains no '/' at a valid position — see sibling errors). Composer packages are always `<vendor>/<package>`, and this adapter refuses to build a Packagist URL without one. The message includes example names.

Source

Thrown at clis/packagist/utils.js:35

    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(`packagist ${label} must be a positive integer`);
    }
    if (n > maxValue) {
        throw new ArgumentError(`packagist ${label} must be <= ${maxValue}`);
    }
    return n;
}

export function requirePackageName(value) {
    const raw = String(value ?? '').trim().toLowerCase();
    if (!raw) {
        throw new ArgumentError('packagist package name is required (e.g. "symfony/console", "monolog/monolog")');
    }
    const slash = raw.indexOf('/');
    if (slash <= 0 || slash === raw.length - 1) {
        throw new ArgumentError(
            `packagist package "${value}" must be "<vendor>/<package>"`,
            'Both segments are required (Composer convention).',
        );
    }
    const vendor = raw.slice(0, slash);
    const pkg = raw.slice(slash + 1);
    if (vendor.length > 100 || pkg.length > 100 || !SEGMENT.test(vendor) || !SEGMENT.test(pkg)) {
        throw new ArgumentError(
            `packagist package "${value}" is not a valid Composer name`,
            'Use lowercase letters / digits / "_-.", segments separated by single "_-." chars (max 100 chars each).',
        );
    }
    return { vendor, package: pkg, full: `${vendor}/${pkg}` };
}

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass a full Composer name like "symfony/console" or "monolog/monolog".
  2. Verify the shell/config variable feeding the argument is actually set.
  3. Catch ArgumentError and print usage showing the vendor/package format.
  4. Prompt the user for the package name if it was not supplied.

Example fix

// before
const name = process.env.PKG ?? '';
await full(name); // empty -> throws

// after
const name = process.env.PKG;
if (!name) throw new Error('Set PKG, e.g. PKG=symfony/console');
await full(name);
Defensive patterns

Strategy: validation

Validate before calling

function looksLikeComposerName(v) {
  return typeof v === 'string' && v.trim().length > 0 && v.includes('/');
}
if (!looksLikeComposerName(name)) {
  throw new Error('expected <vendor>/<package>, e.g. symfony/console');
}

Type guard

const isFilledString = (v) => typeof v === 'string' && v.trim().length > 0;

Try / catch

try {
  await full(name);
} catch (e) {
  if (e instanceof ArgumentError && /package name is required/.test(e.message)) {
    console.error('Usage: packagist full <vendor>/<package>');
    process.exitCode = 2;
  } else throw e;
}

Prevention

When it happens

Trigger: Calling full (which calls requirePackageName) with '', ' ', null, or undefined as the package name, e.g. `packagist full ''`.

Common situations: Shell variable holding the package name is unset/empty ($PKG empty); user forgot the positional argument; JSON/config field missing; template expansion produced an empty string.

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/d0f350aa2d17a7b6. Report an issue: GitHub.