{"record":{"id":"fd05d4155e20066a","repo":"chakra-ui/chakra-ui","slug":"failed-to-search-docs-res-status-res-statust","errorCode":null,"errorMessage":"Failed to search docs: ${res.status} ${res.statusText}","messagePattern":"Failed to search docs: (.+?) (.+?)","errorType":"http","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cli/src/utils/fetch.ts","lineNumber":150,"sourceCode":"  const json: unknown = await res.json()\n  return parseWithSchema(json, z.unknown(), `example for \"${component}\"`)\n}\n\nexport async function fetchTheme() {\n  const res = await request(`${docsUrl(\"/api/theme\")}`)\n  if (!res.ok) {\n    throw new Error(`Failed to fetch theme: ${res.status} ${res.statusText}`)\n  }\n  const json: unknown = await res.json()\n  return parseWithSchema(json, themeIndexSchema, \"theme\")\n}\n\nexport async function searchDocs(query: string): Promise<SearchItem[]> {\n  const res = await request(\n    `${docsUrl(\"/api/search\")}?query=${encodeURIComponent(query)}`,\n  )\n  if (!res.ok) {\n    throw new Error(`Failed to search docs: ${res.status} ${res.statusText}`)\n  }\n  const json: unknown = await res.json()\n  return parseWithSchema(json, searchResultsSchema, \"search\")\n}\n\nexport async function fetchProBlock(\n  category: string,\n  id: string,\n  apiKey: string,\n) {\n  const res = await request(\n    `https://pro.chakra-ui.com/api/blocks/${category}/${id}`,\n    {\n      headers: {\n        \"x-api-key\": apiKey,\n      },\n    },\n  )","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/chakra-ui/chakra-ui/blob/13692aee261402d0f4fd6eeab3a3857afcaae67b/packages/cli/src/utils/fetch.ts#L132-L168","documentation":"Thrown by searchDocs when GET {CHAKRA_DOCS_URL}/api/search?query={query} returns non-2xx. The query is URL-encoded before sending. The message reports status and statusText; a 400/422 can indicate an empty or malformed query, while 5xx indicates the docs origin is down.","triggerScenarios":"GET /api/search?query=... returns non-2xx — most often a 400 for an unsupported/empty query, a 404 if the search path moved, or 5xx during a docs deploy.","commonSituations":"Empty query string passed (encodeURIComponent still yields empty); docs search index rebuilding (5xx); CHAKRA_DOCS_URL misconfigured; search endpoint renamed in a newer docs version; proxy returns an error page.","solutions":["Ensure the query is a non-empty string before calling searchDocs.","Open {CHAKRA_DOCS_URL}/api/search?query=button in a browser to confirm the endpoint.","Retry on 5xx; verify CHAKRA_DOCS_URL is the bare origin.","Upgrade @chakra-ui/cli to align with the current docs search API."],"exampleFix":"// before: empty query can produce a 400\nconst results = await searchDocs(query);\n\n// after: guard the input\nif (!query || !query.trim()) {\n  throw new Error('searchDocs requires a non-empty query');\n}\nconst results = await searchDocs(query.trim());","handlingStrategy":"validation","validationCode":"// Guard the query before calling searchDocs\nfunction isValidQuery(q: unknown): q is string {\n  return typeof q === 'string' && q.trim().length > 0;\n}\nif (!isValidQuery(query)) {\n  throw new Error('searchDocs requires a non-empty query string');\n}","typeGuard":"function isNonEmptyQuery(value: unknown): value is string {\n  return typeof value === 'string' && value.trim().length > 0;\n}","tryCatchPattern":"// Retry transient search failures; surface 4xx as bad-query\ntry {\n  return await searchDocs(query);\n} catch (err) {\n  const msg = (err as Error).message;\n  if (/\\b4\\d\\d\\b/.test(msg) && !/429/.test(msg)) throw new Error('Bad search query');\n  throw err;\n}","preventionTips":["Never pass an empty/blank query to searchDocs.","Trim and length-limit queries before encoding.","Verify the docs search endpoint is up.","Keep CLI and docs versions aligned."],"tags":["cli","docs-api","search","http-status"],"backgroundTag":null,"analyzedSha":"13692aee261402d0f4fd6eeab3a3857afcaae67b","analyzedAt":"2026-08-12T22:25:19.159Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}