jackwener/OpenCLI · error · ArgumentError
rubygems ${label} cannot be empty
Error message
rubygems ${label} cannot be empty What it means
requireString in clis/rubygems/utils.js coerces its argument to a trimmed string and throws ArgumentError('rubygems ${label} cannot be empty') when the result is empty. It is the guard used for required string arguments such as the search query, so the library fails fast instead of issuing a doomed API call.
Source
Thrown at clis/rubygems/utils.js:17
// Shared helpers for the RubyGems.org adapters.
//
// Hits the public, unauthenticated `rubygems.org/api/v1` REST endpoints. No
// auth required for read-only metadata; the API is friendly to anonymous CLI
// traffic. Gem names follow the RubyGems convention: lowercase ASCII +
// `-_.`, 1-100 chars, must start with a letter or digit.
import { ArgumentError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';
export const GEMS_BASE = 'https://rubygems.org/api/v1';
const UA = 'opencli-rubygems-adapter (+https://github.com/jackwener/opencli)';
// RubyGems gem name pattern (mirrors the rubygems-server validation).
const GEM_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
export function requireString(value, label) {
const s = String(value ?? '').trim();
if (!s) throw new ArgumentError(`rubygems ${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(`rubygems ${label} must be a positive integer`);
}
if (n > maxValue) {
throw new ArgumentError(`rubygems ${label} must be <= ${maxValue}`);
}
return n;
}
export function requireGemName(value) {
const s = String(value ?? '').trim();
if (!s) {View on GitHub (pinned to 49907e53dc)
Solutions
- Supply a non-empty value for the flagged argument, e.g. `opencli rubygems search --query rails`.
- Check the variable feeding the argument: `echo "$QUERY"` to confirm it is not empty before invoking.
- In calling code, default or prompt for the value: args.query ||= (await prompt('query:')).
Example fix
// before
await search({ query: '' }); // throws
// after
const query = (process.argv[2] || '').trim();
if (!query) throw new Error('usage: rubygems search <query>');
await search({ query }); Defensive patterns
Strategy: validation
Validate before calling
function requireQuery(q) {
const s = String(q ?? '').trim();
if (!s) throw new Error('query must be a non-empty string');
return s;
} Type guard
function isNonEmptyString(v) {
return typeof v === 'string' && v.trim().length > 0;
} Try / catch
try {
await search({ query: args.query });
} catch (e) {
if (e instanceof ArgumentError && /cannot be empty/.test(e.message)) {
console.error('Provide a search term, e.g. --query rails');
process.exitCode = 2;
} else throw e;
} Prevention
- Always validate CLI args with a usage guard before invoking library calls.
- Check shell variables for emptiness (`: "${QUERY:?query required}"`) in scripts.
- Trim user input before passing it on.
When it happens
Trigger: requireString(value, label) receives null, undefined, an empty string, or whitespace-only input; e.g. search({ query: '' }) or search({}) where query is undefined (label 'query').
Common situations: Forgetting to pass the query flag on the CLI (`opencli rubygems search` with no argument); a shell variable holding the query being unset/empty; passing an empty array/object that stringifies to ''.
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
- rubygems gem name is required (e.g. "rails", "sidekiq")
- rubygems gem "${value}" is not a valid gem name
- --limit must be a positive integer, got ${JSON.stringify(kwa
- `endoflife ${label} must be <= ${maxValue}`
- facebook search --limit must be an integer between 1 and ${M
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/322796ebab97a72a.
Report an issue: GitHub.