jackwener/OpenCLI · error · ArgumentError

rubygems gem name is required (e.g. "rails", "sidekiq")

Error message

rubygems gem name is required (e.g. "rails", "sidekiq")

What it means

requireGemName in clis/rubygems/utils.js throws ArgumentError('rubygems gem name is required (e.g. "rails", "sidekiq")') when the gem-name argument is null, undefined, or an empty/whitespace string. Gem-based commands (info, versions, etc.) require an explicit gem name, so the library fails fast with usage hints.

Source

Thrown at clis/rubygems/utils.js:36

    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) {
        throw new ArgumentError('rubygems gem name is required (e.g. "rails", "sidekiq")');
    }
    if (s.length > 100 || !GEM_NAME.test(s)) {
        throw new ArgumentError(
            `rubygems gem "${value}" is not a valid gem name`,
            'Use letters / digits / "._-", starting with a letter or digit (max 100 chars).',
        );
    }
    return s;
}

export async function gemsFetch(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}`,

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass the gem name explicitly: `opencli rubygems info rails`.
  2. Verify the variable feeding the argument is populated (`echo "$GEM"`).
  3. Add a usage check in your script before invoking: `[ -n "$GEM" ] || { echo 'usage: ... <gem>'; exit 1; }`.

Example fix

// before
await info({ name: '' }); // throws

// after
const name = process.argv[2];
if (!name) {
  console.error('usage: rubygems info <gem>');
  process.exit(1);
}
await info({ name });
Defensive patterns

Strategy: validation

Validate before calling

function requireNameArg(name) {
  const s = String(name ?? '').trim();
  if (!s) throw new Error('gem name is required, e.g. rails or sidekiq');
  return s;
}

Type guard

function isNonEmptyString(v) {
  return typeof v === 'string' && v.trim().length > 0;
}

Try / catch

try {
  await info({ name: args.name });
} catch (e) {
  if (e instanceof ArgumentError && /gem name is required/.test(e.message)) {
    console.error('usage: rubygems info <gem>');
    process.exitCode = 2;
  } else throw e;
}

Prevention

When it happens

Trigger: Calling a gem command without the name argument: gemInfo({}) / gemInfo({ name: '' }) / gemInfo({ name: ' ' }) — requireGemName receives an empty value.

Common situations: Omitting the positional gem argument on the CLI (`opencli rubygems info`); a script variable holding the gem name being unset; piping an empty value into the command.

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


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/3fb3dcaf05b0c324. Report an issue: GitHub.