jackwener/OpenCLI · error · ArgumentError
nuget ${label} cannot be empty
Error message
nuget ${label} cannot be empty What it means
An ArgumentError thrown by requireString when a required string argument (identified by label, e.g. 'query' or 'package id') is empty or whitespace after trimming. It guards entry points like nuget search's query so downstream URL construction and validation never receive blank input.
Source
Thrown at clis/nuget/utils.js:20
//
// NuGet exposes two complementary endpoints:
// • `azuresearch-usnc.nuget.org/query` — full-text package search (V3)
// • `api.nuget.org/v3/registration5-semver1/<id>/index.json` — package detail
// No API key required. Anonymous traffic is generous; we set a polite UA.
import { ArgumentError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';
export const NUGET_SEARCH_BASE = 'https://azuresearch-usnc.nuget.org';
export const NUGET_REGISTRATION_BASE = 'https://api.nuget.org/v3/registration5-semver1';
const UA = 'opencli-nuget-adapter/1.0 (+https://github.com/jackwener/opencli; mailto:opencli@example.com)';
// NuGet ID grammar (NuGet docs §package-id): up to 100 chars, alnum + `.` + `_` + `-`,
// must start with letter/digit. Case-insensitive; we lowercase for the registration URL
// because NuGet's CDN is case-sensitive on the path.
const PACKAGE_ID_PATTERN = /^[A-Za-z0-9](?:[A-Za-z0-9._-]{0,99})$/;
export function requireString(value, label) {
const s = String(value ?? '').trim();
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")');View on GitHub (pinned to 49907e53dc)
Solutions
- Supply a non-empty value for the argument (e.g. pass the actual search query or package id).
- If scripting, quote the argument so the shell doesn't drop it: `cli nuget search "newtonsoft"`.
- Check the environment variable/config source feeding the value — ensure it is set.
- Validate/trim user input before calling, and prompt again if blank.
- In code, fall back to a sensible default or throw a clearer domain error before invoking the library.
Example fix
// before
const q = process.env.SEARCH_QUERY; // may be undefined
await nugetSearch(q); // ArgumentError: nuget query cannot be empty
// after
const q = (process.env.SEARCH_QUERY ?? '').trim();
if (!q) {
console.error('SEARCH_QUERY is required');
process.exit(1);
}
await nugetSearch(q); Defensive patterns
Strategy: validation
Validate before calling
function requireQuery(q) {
if (typeof q !== 'string' || !q.trim()) throw new Error('query must be a non-empty string');
return q.trim();
}
// call: nugetSearch(requireQuery(userInput)) Type guard
function isNonEmptyString(v) {
return typeof v === 'string' && v.trim().length > 0;
} Try / catch
try {
await nugetSearch(query);
} catch (err) {
if (err.name === 'ArgumentError' && String(err.message).includes('cannot be empty')) {
console.error('Please provide a search query, e.g. cli nuget search "newtonsoft"');
} else throw err;
} Prevention
- Quote arguments in shell scripts so they are never dropped.
- Validate and trim user input before calling library functions.
- Check that env/config values feeding arguments are set.
- Provide CLI-level usage checks that fail with a helpful message before reaching the library.
When it happens
Trigger: Calling a command that routes through requireString with an empty string, whitespace-only string, null, or undefined for the labeled argument — e.g. nugetSearch('') or nugetSearch(null) reaching the query handler.
Common situations: Shell invocation with a missing quoted argument (e.g. `cli nuget search` with no query); environment-driven input where a variable is unset; programmatic calls passing null/undefined; user-submitted form values that are blank after trim().
Related errors
- station must not be empty
- ${label} cannot be empty
- crates ${label} cannot be empty
- Instagram note content cannot be empty.
- --keywords is required
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/46b2aedc7d520db5.
Report an issue: GitHub.