{"record":{"id":"75221fcf8840544b","repo":"jackwener/OpenCLI","slug":"mdn-search-request-failed-err-message-err","errorCode":null,"errorMessage":"mdn search request failed: ${err?.message ?? err}","messagePattern":"mdn search request failed: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/mdn/search.js","lineNumber":66,"sourceCode":"    strategy: Strategy.PUBLIC,\n    browser: false,\n    args: [\n        { name: 'query', positional: true, required: true, help: 'Search keyword (e.g. \"fetch\", \"flexbox\", \"Array.prototype.map\")' },\n        { name: 'limit', type: 'int', default: 10, help: 'Max results (1-50)' },\n        { name: 'locale', default: 'en-US', help: 'Doc locale (en-US default; de / es / fr / ja / ko / pt-BR / ru / zh-CN / zh-TW)' },\n    ],\n    columns: ['rank', 'title', 'slug', 'locale', 'summary', 'url'],\n    func: async (args) => {\n        const query = requireString(args.query, 'query');\n        const limit = requireBoundedInt(args.limit, 10, 50);\n        const locale = requireLocale(args.locale);\n        const url = `${MDN_BASE}/api/v1/search?q=${encodeURIComponent(query)}&locale=${encodeURIComponent(locale)}&size=${limit}`;\n        let resp;\n        try {\n            resp = await fetch(url, { headers: { 'user-agent': UA, accept: 'application/json' } });\n        }\n        catch (err) {\n            throw new CommandExecutionError(`mdn search request failed: ${err?.message ?? err}`);\n        }\n        if (resp.status === 429) {\n            throw new CommandExecutionError(\n                'mdn search returned HTTP 429 (rate limited)',\n                'MDN throttles bursty traffic; wait a few seconds and retry.',\n            );\n        }\n        if (!resp.ok) {\n            throw new CommandExecutionError(`mdn search returned HTTP ${resp.status}`);\n        }\n        let body;\n        try {\n            body = await resp.json();\n        }\n        catch (err) {\n            throw new CommandExecutionError(`mdn search returned malformed JSON: ${err?.message ?? err}`);\n        }\n        const docs = Array.isArray(body?.documents) ? body.documents : [];","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/mdn/search.js#L48-L84","documentation":"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.","triggerScenarios":"No network connectivity; DNS resolution failure for developer.mozilla.org; proxy/firewall blocking HTTPS; offline machine; Node fetch TLS/certificate issues.","commonSituations":"Working offline or on flaky Wi-Fi; corporate proxy intercepting TLS; VPN drops mid-session; container without network access.","solutions":["Check network connectivity (curl https://developer.mozilla.org/api/v1/search?q=test).","Fix DNS/proxy configuration (set HTTPS_PROXY or corporate CA if needed).","Retry after connectivity is restored — the error is transient.","Read the wrapped err.message in the error text to identify the exact low-level cause (ENOTFOUND, ECONNREFUSED, CERT_...)."],"exampleFix":"// before\nawait mdnSearch({ query: 'css grid' }); // throws when offline\n// after\ntry {\n  return await mdnSearch({ query: 'css grid' });\n} catch (e) {\n  if (String(e.message).includes('request failed')) return cachedResults();\n  throw e;\n}","handlingStrategy":"retry","validationCode":"const online = await fetch('https://developer.mozilla.org', { method: 'HEAD' }).then(() => true, () => false);\nif (!online) throw new Error('offline: mdn search unavailable');","typeGuard":null,"tryCatchPattern":"try { return await mdnSearch({ query }); } catch (e) { if (String(e.message).includes('request failed')) { await sleep(1000); return retry(upTo = 3); } throw e; }","preventionTips":["Check connectivity before batch operations","Configure proxy/TLS settings for corporate networks","Implement exponential backoff retries","Cache results to tolerate outages"],"tags":["network","http","fetch","cli"],"backgroundTag":"fetch-network-error","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}