jackwener/OpenCLI · error · ArgumentError
rest-countries ${label} cannot be empty
Error message
rest-countries ${label} cannot be empty What it means
requireString validates that a labeled string argument is non-empty after trimming; otherwise it throws ArgumentError with 'rest-countries ${label} cannot be empty'. It is a guard so commands fail fast with a clear message instead of building malformed URLs. `value ?? ''` means null/undefined also trigger it.
Source
Thrown at clis/rest-countries/utils.js:24
import { ArgumentError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';
export const REST_COUNTRIES_BASE = 'https://restcountries.com/v3.1';
const UA = 'opencli-rest-countries-adapter/1.0 (+https://github.com/jackwener/opencli; mailto:opencli@example.com)';
// REST Countries valid region values; subregions are validated server-side.
export const REST_COUNTRIES_REGIONS = new Set(['africa', 'americas', 'asia', 'europe', 'oceania', 'antarctic']);
// Fields the adapter always requests; keep this list aligned with `columns` so
// rows never have null-where-absent silent drops.
export const COUNTRY_FIELDS = [
'name', 'cca2', 'cca3', 'ccn3', 'capital', 'region', 'subregion',
'population', 'area', 'languages', 'currencies', 'flag', 'latlng', 'timezones',
'independent', 'unMember', 'landlocked',
].join(',');
export function requireString(value, label) {
const s = String(value ?? '').trim();
if (!s) throw new ArgumentError(`rest-countries ${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(`rest-countries ${label} must be a positive integer`);
}
if (n > maxValue) {
throw new ArgumentError(`rest-countries ${label} must be <= ${maxValue}`);
}
return n;
}
export function requireRegion(value) {
const raw = String(value ?? '').trim().toLowerCase();
if (!raw) throw new ArgumentError('rest-countries region is required (e.g. "europe", "asia")');View on GitHub (pinned to 49907e53dc)
Solutions
- Pass a non-empty `name` argument to the country command.
- Check the calling script/config for unset or empty variables feeding the name.
- Validate required inputs before invoking the command.
- Catch ArgumentError and print usage help.
Example fix
// before
await countryCommand({ name: process.env.COUNTRY ?? '' });
// after
if (!process.env.COUNTRY) throw new Error('COUNTRY env var is required');
await countryCommand({ name: process.env.COUNTRY }); Defensive patterns
Strategy: validation
Validate before calling
if (typeof name !== 'string' || name.trim() === '') {
throw new TypeError('name is required and must be a non-empty string');
} Type guard
function isNonEmptyString(v) { return typeof v === 'string' && v.trim().length > 0; } Try / catch
try {
await countryCommand({ name });
} catch (err) {
if (err instanceof ArgumentError && /cannot be empty/.test(err.message)) {
printUsage('name is required');
} else {
throw err;
}
} Prevention
- Validate all required CLI args before invoking commands.
- Never pass process.env values directly without an emptiness check.
- Default missing required inputs to prompts or hard failures, not ''.
- Write integration tests for the missing-argument path.
When it happens
Trigger: Calling the rest-countries country command without a `name` argument, or with name = '' / whitespace / null, so `String(value ?? '').trim()` is empty at clis/rest-countries/utils.js:24.
Common situations: Missing CLI flag or config key; passing an empty environment variable; a script interpolating an unset variable into the name argument.
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
- rest-countries region is required (e.g. "europe", "asia")
- archive search sort must be one of ${SORT_OPTIONS.join(', ')
- archive search mediatype must be one of ${MEDIATYPES.join(',
- archive search limit must be a positive integer
- archive search limit must be <= 100
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/88b43b37e090119f.
Report an issue: GitHub.