{"record":{"id":"2e3d8d4f680cb6e2","repo":"jackwener/OpenCLI","slug":"duckduckgo-suggest-request-failed-err-instanceo","errorCode":null,"errorMessage":"DuckDuckGo suggest request failed: ${err instanceof Error ? err.message : String(err)}","messagePattern":"DuckDuckGo suggest request failed: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/duckduckgo/suggest.js","lineNumber":26,"sourceCode":"  access: 'read',\n  description: 'DuckDuckGo search suggestions',\n  domain: 'duckduckgo.com',\n  strategy: Strategy.PUBLIC,\n  browser: false,\n  args: [\n    { name: 'keyword', positional: true, required: true, help: 'Search query prefix' },\n    { name: 'limit', type: 'int', default: 8, help: 'Max number of suggestions' },\n  ],\n  columns: ['phrase'],\n  func: async (kwargs) => {\n    const limit = requireBoundedInteger(kwargs.limit, 8, 1, 20, '--limit');\n    const keyword = encodeURIComponent(requireSearchQuery(kwargs.keyword));\n    const url = `https://duckduckgo.com/ac/?q=${keyword}&type=list`;\n    let resp;\n    try {\n      resp = await fetch(url);\n    } catch (err) {\n      throw new CommandExecutionError(`DuckDuckGo suggest request failed: ${err instanceof Error ? err.message : String(err)}`);\n    }\n    if (!resp.ok) {\n      throw new CommandExecutionError(`DuckDuckGo suggest returned HTTP ${resp.status}`);\n    }\n    let data;\n    try {\n      data = await resp.json();\n    } catch (err) {\n      throw new CommandExecutionError(`DuckDuckGo suggest returned malformed JSON: ${err?.message ?? err}`);\n    }\n    const phrases = Array.isArray(data) && data.length > 1 && Array.isArray(data[1]) ? data[1] : [];\n    return phrases\n      .filter((phrase) => typeof phrase === 'string' && phrase.trim())\n      .slice(0, limit)\n      .map(function(p) { return { phrase: p }; });\n  },\n});\n","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/duckduckgo/suggest.js#L8-L44","documentation":"The DuckDuckGo suggest command fetches https://duckduckgo.com/ac/ to get autocomplete phrases. If the fetch itself rejects (network unreachable, DNS failure, TLS error, aborted request), the error is wrapped in a CommandExecutionError whose message embeds the original error's message. This distinguishes transport-level failures from HTTP status errors and JSON parse failures.","triggerScenarios":"fetch() rejects when calling the suggest endpoint: no internet, DNS resolution failure, connection refused/reset, TLS/certificate problems, or request timeout/abort.","commonSituations":"Running in an offline or air-gapped environment; corporate proxy/firewall blocking duckduckgo.com; DNS misconfiguration; IPv6 issues; transient network outage in CI.","solutions":["Check network connectivity and that duckduckgo.com is reachable (curl https://duckduckgo.com/ac/?q=test&type=list)","Configure proxy environment variables (HTTPS_PROXY) if behind a firewall","Retry — many failures are transient; add backoff","Catch CommandExecutionError and surface a 'network unavailable' message to users","Pin/fix TLS/DNS settings if the embedded message indicates a certificate or DNS problem"],"exampleFix":"// before\nconst s = await ddgSuggest({ keyword: 'cats' }); // throws on network error\n// after\ntry {\n  const s = await ddgSuggest({ keyword: 'cats' });\n} catch (err) {\n  if (err.message.includes('suggest request failed')) return []; // offline: no suggestions\n  throw err;\n}","handlingStrategy":"retry","validationCode":"// probe connectivity first\nconst ok = await fetch('https://duckduckgo.com', { method: 'HEAD' }).then(r => r.ok).catch(() => false);\nif (!ok) throw new Error('duckduckgo.com unreachable — check network/proxy');","typeGuard":null,"tryCatchPattern":"try {\n  return await ddgSuggest({ keyword });\n} catch (err) {\n  if (/suggest request failed/.test(err?.message ?? '')) {\n    await sleep(1000);\n    return ddgSuggest({ keyword }); // one retry for transient network issues\n  }\n  throw err;\n}","preventionTips":["Configure HTTPS_PROXY in restricted environments","Add exponential backoff around network calls","Check DNS/VPN when running in CI or corporate networks","Fail soft (return []) when suggestions are optional"],"tags":["network","fetch-failed","cli"],"backgroundTag":"fetch-request-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}