jackwener/OpenCLI · error · ArgumentError
pypi package name is required (e.g. "requests", "pandas")
Error message
pypi package name is required (e.g. "requests", "pandas")
What it means
ArgumentError thrown by requirePackageName when the package name argument is empty or missing. The helper trims the input and rejects blank strings before any network request is made. It fails fast with an example-bearing message so users know the expected input format.
Source
Thrown at clis/pypi/utils.js:14
// Shared helpers for the pypi adapters that hit the PyPI public JSON API
// (pypi.org/pypi/<pkg>/json) and pypistats.org for download stats.
import { ArgumentError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';
export const PYPI_BASE = 'https://pypi.org';
export const PYPISTATS_BASE = 'https://pypistats.org';
const UA = 'opencli-pypi-adapter (+https://github.com/jackwener/opencli)';
// PEP 508 / PEP 426 normalized name: letters, digits, "._-", with leading-letter rule relaxed by PyPI.
const PKG_NAME = /^[A-Za-z0-9]([A-Za-z0-9._-]*[A-Za-z0-9])?$/;
export function requirePackageName(value) {
const s = String(value ?? '').trim();
if (!s) throw new ArgumentError('pypi package name is required (e.g. "requests", "pandas")');
if (!PKG_NAME.test(s)) {
throw new ArgumentError(
`pypi package name "${value}" is not a valid distribution name`,
'PyPI accepts ASCII letters / digits / "._-" with no leading or trailing separator.',
);
}
return s;
}
export async function pypiFetch(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 pypi.org / pypistats.org are reachable from this network.',View on GitHub (pinned to 49907e53dc)
Solutions
- Pass a package name explicitly, e.g. `pypi package requests`
- Check the variable holding the name is set and non-empty
- Validate required inputs in the calling script before invoking the CLI
Example fix
// before
const name = process.env.PKG; // may be undefined
await pypiPackage(name);
// after
if (!process.env.PKG) throw new Error('PKG env var required');
await pypiPackage(process.env.PKG); Defensive patterns
Strategy: validation
Validate before calling
const name = (process.argv[2] ?? '').trim();
if (!name) {
console.error('Usage: pypi package <name>');
process.exit(2);
} Type guard
function isNonEmptyString(v) { return typeof v === 'string' && v.trim().length > 0; } Try / catch
try {
await pypiPackage(name);
} catch (e) {
if (/name is required/i.test(e.message)) {
console.error('Provide a package name, e.g. pypi package requests');
} else throw e;
} Prevention
- Always validate CLI args before invoking the API
- Check env/script variables for emptiness with ${VAR:?} guards in bash
- Require explicit names in automation rather than relying on defaults
When it happens
Trigger: Calling a pypi CLI subcommand (e.g. `pypi package`, which calls requirePackageName via the `name` arg) with an empty string, whitespace-only string, null, or undefined name.
Common situations: Forgetting the positional argument in a script; a shell variable that resolves to empty (`pypi package "$PKG"` with unset PKG); piping config with a missing name field.
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
- symbol is required
- boss ${name} cannot be empty
- <username> is required
- <game-url> is required
- Either --product-id or --url is required
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/636675c6f3971407.
Report an issue: GitHub.