jackwener/OpenCLI · error · ArgumentError

homebrew ${label} is required (e.g. "wget", "gcc@13", "firef

Error message

homebrew ${label} is required (e.g. "wget", "gcc@13", "firefox")

What it means

requireToken throws ArgumentError('homebrew <label> is required (e.g. "wget", "gcc@13", "firefox")') when the token argument (formula or cask name) is missing or empty after trimming. It is the friendly 'you forgot the argument' guard for token-taking commands like info/search.

Source

Thrown at clis/homebrew/utils.js:37

    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(`homebrew ${label} must be a positive integer`);
    }
    if (n > maxValue) {
        throw new ArgumentError(`homebrew ${label} must be <= ${maxValue}`);
    }
    return n;
}

export function requireToken(value, label) {
    const s = String(value ?? '').trim();
    if (!s) {
        throw new ArgumentError(`homebrew ${label} is required (e.g. "wget", "gcc@13", "firefox")`);
    }
    if (s.length > 100 || !TOKEN.test(s)) {
        throw new ArgumentError(
            `homebrew ${label} "${value}" is not a valid token`,
            'Use letters / digits / "_-.+@", starting with a letter or digit (max 100 chars).',
        );
    }
    return s;
}

export function requireOneOf(value, allowed, label) {
    const s = String(value ?? '').trim().toLowerCase();
    if (!s) throw new ArgumentError(`homebrew ${label} is required`);
    if (!allowed.includes(s)) {
        throw new ArgumentError(
            `homebrew ${label} "${value}" is not supported`,
            `Allowed: ${allowed.join(', ')}.`,
        );

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Supply a formula or cask token, e.g. `homebrew info wget`
  2. Check that the variable feeding the token is set and non-empty
  3. Validate non-empty input before invoking the command
  4. Catch ArgumentError and show the usage hint included in the error

Example fix

// before
await homebrewInfo(process.argv[3]);
// after
const token = (process.argv[3] ?? '').trim();
if (!token) {
  console.error('Usage: homebrew info <formula|cask>');
  process.exit(2);
}
await homebrewInfo(token);
Defensive patterns

Strategy: validation

Validate before calling

const token = String(rawToken ?? '').trim();
if (!token) {
  console.error('Usage: homebrew <command> <formula|cask>  e.g. homebrew info wget');
  process.exit(2);
}

Type guard

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

Try / catch

try {
  await homebrewInfo(rawToken);
} catch (err) {
  if (err instanceof ArgumentError && /is required/.test(err.message)) {
    console.error(err.message + '\n' + (err.hint ?? ''));
    process.exitCode = 2;
    return;
  }
  throw err;
}

Prevention

When it happens

Trigger: Running a command without its token argument (e.g. `homebrew info` with no name), or passing an empty/whitespace string or null/undefined programmatically.

Common situations: Scripts calling the API with an unset variable, CLI users omitting the positional argument, quoting errors that swallow the value.

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/ae3ecb4cd82a9b26. Report an issue: GitHub.