jackwener/OpenCLI · error · ArgumentError

homebrew ${label} is required

Error message

homebrew ${label} is required

What it means

requireOneOf validates that an enum-like option (e.g. the `type` or `window` argument of homebrew commands) is a non-empty string belonging to a fixed allow-list. The library throws this ArgumentError when the value normalizes (trim + lowercase) to an empty string — meaning the argument was omitted, undefined/null, or whitespace-only. It fails fast at argument-validation time instead of sending a malformed request to the Homebrew API.

Source

Thrown at clis/homebrew/utils.js:50

}

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(', ')}.`,
        );
    }
    return s;
}

export async function brewFetch(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}`,
            'Check that formulae.brew.sh is reachable from this network.',

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass one of the allowed values for the argument (e.g. type 'formula' or 'cask', a valid analytics window) instead of leaving it empty.
  2. Check the calling script for unset/empty shell or config variables and add a default (e.g. TYPE=${TYPE:-formula}).
  3. Read the error's label to see which argument is missing and consult the command's allowed-values list (the companion 'is not supported' error lists them).

Example fix

// before
homebrew popular --type "$TYPE" --window "$WINDOW"   # $TYPE unset -> ArgumentError
// after
homebrew popular --type "${TYPE:-formula}" --window "${WINDOW:-30d}"
Defensive patterns

Strategy: validation

Validate before calling

const HOMEBREW_TYPES = ['formula', 'cask'];
function validateType(value) {
  const s = String(value ?? '').trim().toLowerCase();
  if (!s) throw new Error(`homebrew type is required (one of: ${HOMEBREW_TYPES.join(', ')})`);
  return s;
}

Type guard

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

Try / catch

try {
  await run({ type });
} catch (err) {
  if (err instanceof ArgumentError && err.message.includes('is required')) {
    type = 'formula'; // default and retry
  } else throw err;
}

Prevention

When it happens

Trigger: Calling a homebrew command/function that routes through requireOneOf with the labeled argument missing: e.g. type(undefined), type(''), type(' '), type(null), or window(null). Any falsy-after-trim value produces this error.

Common situations: Scripting the CLI where a shell variable holding the type/window is unset or empty ($TYPE expands to nothing); programmatic use passing null/undefined because an upstream lookup failed; typo of the parameter name so the expected key never reaches the function.

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