jackwener/OpenCLI · error · CommandExecutionError

mdn search request failed: ${err?.message ?? err}

Error message

mdn search request failed: ${err?.message ?? err}

What it means

The MDN adapter calls fetch against developer.mozilla.org's search API. If fetch itself rejects (network unreachable, DNS failure, TLS error, connection reset), the adapter wraps the underlying error message in a CommandExecutionError. It indicates the request never completed, not an HTTP error status.

Source

Thrown at clis/mdn/search.js:66

    strategy: Strategy.PUBLIC,
    browser: false,
    args: [
        { name: 'query', positional: true, required: true, help: 'Search keyword (e.g. "fetch", "flexbox", "Array.prototype.map")' },
        { name: 'limit', type: 'int', default: 10, help: 'Max results (1-50)' },
        { name: 'locale', default: 'en-US', help: 'Doc locale (en-US default; de / es / fr / ja / ko / pt-BR / ru / zh-CN / zh-TW)' },
    ],
    columns: ['rank', 'title', 'slug', 'locale', 'summary', 'url'],
    func: async (args) => {
        const query = requireString(args.query, 'query');
        const limit = requireBoundedInt(args.limit, 10, 50);
        const locale = requireLocale(args.locale);
        const url = `${MDN_BASE}/api/v1/search?q=${encodeURIComponent(query)}&locale=${encodeURIComponent(locale)}&size=${limit}`;
        let resp;
        try {
            resp = await fetch(url, { headers: { 'user-agent': UA, accept: 'application/json' } });
        }
        catch (err) {
            throw new CommandExecutionError(`mdn search request failed: ${err?.message ?? err}`);
        }
        if (resp.status === 429) {
            throw new CommandExecutionError(
                'mdn search returned HTTP 429 (rate limited)',
                'MDN throttles bursty traffic; wait a few seconds and retry.',
            );
        }
        if (!resp.ok) {
            throw new CommandExecutionError(`mdn search returned HTTP ${resp.status}`);
        }
        let body;
        try {
            body = await resp.json();
        }
        catch (err) {
            throw new CommandExecutionError(`mdn search returned malformed JSON: ${err?.message ?? err}`);
        }
        const docs = Array.isArray(body?.documents) ? body.documents : [];

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Check network connectivity (curl https://developer.mozilla.org/api/v1/search?q=test).
  2. Fix DNS/proxy configuration (set HTTPS_PROXY or corporate CA if needed).
  3. Retry after connectivity is restored — the error is transient.
  4. Read the wrapped err.message in the error text to identify the exact low-level cause (ENOTFOUND, ECONNREFUSED, CERT_...).

Example fix

// before
await mdnSearch({ query: 'css grid' }); // throws when offline
// after
try {
  return await mdnSearch({ query: 'css grid' });
} catch (e) {
  if (String(e.message).includes('request failed')) return cachedResults();
  throw e;
}
Defensive patterns

Strategy: retry

Validate before calling

const online = await fetch('https://developer.mozilla.org', { method: 'HEAD' }).then(() => true, () => false);
if (!online) throw new Error('offline: mdn search unavailable');

Try / catch

try { return await mdnSearch({ query }); } catch (e) { if (String(e.message).includes('request failed')) { await sleep(1000); return retry(upTo = 3); } throw e; }

Prevention

When it happens

Trigger: No network connectivity; DNS resolution failure for developer.mozilla.org; proxy/firewall blocking HTTPS; offline machine; Node fetch TLS/certificate issues.

Common situations: Working offline or on flaky Wi-Fi; corporate proxy intercepting TLS; VPN drops mid-session; container without network access.

Related errors


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