jackwener/OpenCLI · error · ArgumentError
packagist ${label} cannot be empty
Error message
packagist ${label} cannot be empty What it means
The Packagist adapter's requireString helper normalizes its input with String(value ?? '').trim() and throws this ArgumentError when the result is empty. It is a guard ensuring required string arguments (labeled via `label`) are non-empty before any API work happens. Throwing early keeps callers from sending meaningless requests to packagist.org.
Source
Thrown at clis/packagist/utils.js:16
// Shared helpers for the Packagist (PHP / Composer) adapters.
//
// Hits the public, unauthenticated `packagist.org` JSON endpoints. Composer's
// canonical package registry. Package names are `<vendor>/<package>`,
// lowercase letters / digits / `_-.`, with each segment 1-100 chars.
import { ArgumentError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';
export const PACKAGIST_BASE = 'https://packagist.org';
const UA = 'opencli-packagist-adapter (+https://github.com/jackwener/opencli)';
// Each segment of a Composer package name (`vendor` and `package`).
const SEGMENT = /^[a-z0-9]([_.-]?[a-z0-9]+)*$/;
export function requireString(value, label) {
const s = String(value ?? '').trim();
if (!s) throw new ArgumentError(`packagist ${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(`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) {View on GitHub (pinned to 49907e53dc)
Solutions
- Provide a non-empty value for the labeled argument before calling query().
- If the value comes from env/config, check it is set and non-blank (not just truthy after coercion).
- Catch ArgumentError in your entry point and print usage help prompting for the missing value.
- Trim user input and re-prompt if the trimmed result is empty.
Example fix
// before
await query(opts.q, { limit: 10 }); // opts.q may be undefined
// after
if (!opts.q || !opts.q.trim()) {
throw new Error('Usage: packagist query <term>');
}
await query(opts.q.trim(), { limit: 10 }); Defensive patterns
Strategy: validation
Validate before calling
function hasQuery(v) {
return typeof v === 'string' && v.trim().length > 0;
}
if (!hasQuery(term)) throw new Error('query term required'); Type guard
const isNonEmptyString = (v) => typeof v === 'string' && v.trim().length > 0;
Try / catch
try {
await query(term);
} catch (e) {
if (e instanceof ArgumentError && /cannot be empty/.test(e.message)) {
console.error('A query term is required.');
process.exitCode = 2;
} else throw e;
} Prevention
- Validate CLI args with a parser (yargs/commander) that enforces required arguments.
- Trim all user input and treat whitespace-only as missing.
- Check env/config values at startup, not at call time.
- Require arguments explicitly in scripts with a usage() guard.
When it happens
Trigger: Calling query() (via requireString) with an empty string, whitespace-only string, null, or undefined for a required labeled parameter, e.g. requireString(searchParams.get('q'), 'query') where the query parameter is missing.
Common situations: CLI invoked without a required positional argument; an env var or config key holding an empty string; upstream code passing null/undefined instead of a value; user pressing enter on an empty prompt.
Related errors
- ${label} cannot be empty
- Instagram note content cannot be empty.
- prompt cannot be empty
- No fids provided
- --approve-kinds must contain at least one approval kind
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/f7a7cb5c2517fd3b.
Report an issue: GitHub.