jackwener/OpenCLI · error · CommandExecutionError

${label} request failed: ${err?.message ?? err}

Error message

${label} request failed: ${err?.message ?? err}

What it means

brewFetch wraps all network calls to formulae.brew.sh. If fetch() itself rejects — DNS failure, connection refused, TLS error, offline machine — the library converts the raw TypeError into a CommandExecutionError with the original message and a hint to check network reachability of formulae.brew.sh. This distinguishes transport-level failures from HTTP error statuses.

Source

Thrown at clis/homebrew/utils.js:66

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.',
        );
    }
    if (resp.status === 404) {
        throw new EmptyResultError(label, `Homebrew API returned 404 for ${url}.`);
    }
    if (resp.status === 429) {
        throw new CommandExecutionError(
            `${label} returned HTTP 429 (rate limited)`,
            'Homebrew throttles bursts; wait a few seconds and retry.',
        );
    }
    if (!resp.ok) {
        throw new CommandExecutionError(`${label} returned HTTP ${resp.status}`);
    }
    let body;
    try {

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Verify basic connectivity: curl https://formulae.brew.sh/api/formula/wget.json should return JSON.
  2. Check proxy/VPN/firewall settings and set HTTPS_PROXY correctly if the network requires one.
  3. Retry after confirming the network is back; the failure is usually transient (offline, captive portal).
  4. If the host is permanently blocked, mirror the API JSON locally and point the adapter at the mirror.

Example fix

// before
const data = await brewFetch(`${BREW_BASE}/formula/${token}.json`, 'formula info'); // throws offline
// after
try {
  const data = await brewFetch(`${BREW_BASE}/formula/${token}.json`, 'formula info');
} catch (err) {
  if (err instanceof CommandExecutionError && /request failed/.test(err.message)) {
    // offline / DNS / proxy: alert or fall back to cached data
  }
  throw err;
}
Defensive patterns

Strategy: retry

Validate before calling

async function canReachBrewApi() {
  try {
    const r = await fetch('https://formulae.brew.sh/api/formula/wget.json', { method: 'HEAD' });
    return r.ok || r.status === 404; // reachable either way
  } catch { return false; }
}
if (!(await canReachBrewApi())) throw new Error('formulae.brew.sh unreachable — check network/proxy');

Type guard

null

Try / catch

try {
  const data = await brewFetch(url, label);
} catch (err) {
  if (err instanceof CommandExecutionError && /request failed/.test(err.message)) {
    await sleep(2000);
    return brewFetch(url, label); // one retry after transient network failure
  }
  throw err;
}

Prevention

When it happens

Trigger: Calling any homebrew adapter function that ends in brewFetch (formula/cask info, popular analytics) while the network is down, DNS cannot resolve formulae.brew.sh, a corporate proxy/firewall blocks the host, or TLS interception breaks the handshake.

Common situations: CI runners without egress to GitHub Pages (the API is served from there); laptops on VPNs or captive-portal Wi-Fi; offline development; typo'd corporate proxy env vars breaking Node's fetch.

Related errors


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