jackwener/OpenCLI · error · CommandExecutionError

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

Error message

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

What it means

gemsFetch in clis/rubygems/utils.js wraps global fetch; when the fetch itself rejects (network unreachable, DNS failure, TLS error, connection refused) it throws CommandExecutionError(`${label} request failed: ${err?.message ?? err}`) with a hint to check that rubygems.org is reachable. The library converts the raw fetch exception so every command surfaces a consistent, labeled message.

Source

Thrown at clis/rubygems/utils.js:53

    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}`,
            'Check that rubygems.org is reachable from this network.',
        );
    }
    if (resp.status === 404) {
        throw new EmptyResultError(label, `RubyGems returned 404 for ${url}.`);
    }
    if (resp.status === 429) {
        throw new CommandExecutionError(
            `${label} returned HTTP 429 (rate limited)`,
            'RubyGems 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 reachability: `curl -sv https://rubygems.org/api/v1/search.json?query=rails` — compare its error with the one in the message.
  2. Check DNS: `nslookup rubygems.org`; try `--dns-over-https` style fixes or a different resolver if it fails.
  3. Configure proxy env vars (HTTPS_PROXY/NO_PROXY) so fetch can route out, or bypass a broken corporate proxy.
  4. Retry after checking status — transient blips resolve with one retry; wrap the call in retry-with-backoff.

Example fix

// before
await search({ query: 'rails' }); // CommandExecutionError: request failed

// after
async function withRetry(fn, n = 3) {
  for (let i = 0; i < n; i++) {
    try { return await fn(); }
    catch (e) {
      if (i === n - 1 || !/request failed/.test(e.message)) throw e;
      await new Promise(r => setTimeout(r, 2 ** i * 500));
    }
  }
}
await withRetry(() => search({ query: 'rails' }));
Defensive patterns

Strategy: retry

Validate before calling

// Pre-flight reachability probe
const probe = await fetch('https://rubygems.org/api/v1/rubygems.json')
  .then(r => r.ok).catch(() => false);
if (!probe) throw new Error('rubygems.org unreachable — check network/proxy');

Type guard

function isFetchNetworkError(err) {
  return err instanceof TypeError || /fetch failed|ENOTFOUND|ECONNREFUSED|ECONNRESET|certificate/i.test(String(err?.cause ?? err));
}

Try / catch

async function gemsFetchRetry(url, label, tries = 3) {
  for (let i = 0; ; i++) {
    try { return await gemsFetch(url, label); }
    catch (e) {
      if (i >= tries - 1 || !/request failed/.test(e.message)) throw e;
      await new Promise(r => setTimeout(r, 2 ** i * 500 + Math.random() * 250));
    }
  }
}

Prevention

When it happens

Trigger: Any rubygems command (search, gem info, etc.) when the initial fetch() to rubygems.org throws: offline machine, DNS failure, blocked firewall/proxy, TLS interception failure.

Common situations: Corporate firewall blocking rubygems.org; no internet/VPN in CI; DNS misconfiguration; self-signed corporate TLS proxy rejecting the connection; IPv6-only breakage.

Related errors


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