{"record":{"id":"2bdf5a68009a4af2","repo":"can1357/oh-my-pi","slug":"jina-api-returned-invalid-response-expected-data","errorCode":null,"errorMessage":"Jina API returned invalid response: expected data array","messagePattern":"Jina API returned invalid response: expected data array","errorType":"validation","errorClass":"SearchProviderError","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/web/search/providers/jina.ts","lineNumber":89,"sourceCode":"\t});\n\n\tif (!response.ok) {\n\t\tconst errorText = await response.text();\n\t\tconst classified = classifyProviderHttpError(\"jina\", response.status, errorText);\n\t\tif (classified) throw classified;\n\t\tthrow new SearchProviderError(\"jina\", `Jina API error (${response.status}): ${errorText}`, response.status);\n\t}\n\n\tconst payload = (await response.json()) as JinaSearchEnvelope | JinaSearchResponse | null;\n\tif (Array.isArray(payload)) return payload;\n\tif (!payload || typeof payload !== \"object\") {\n\t\tthrow new SearchProviderError(\"jina\", \"Jina API returned invalid response: expected an object or array\");\n\t}\n\tif (typeof payload.code === \"number\" && payload.code !== 200) {\n\t\tthrow new SearchProviderError(\"jina\", `Jina API response reported failure (${payload.code})`, payload.code);\n\t}\n\tif (!Array.isArray(payload.data)) {\n\t\tthrow new SearchProviderError(\"jina\", \"Jina API returned invalid response: expected data array\");\n\t}\n\treturn payload.data as JinaSearchResponse;\n}\n\n/** Execute Jina web search. */\nexport async function searchJina(params: JinaSearchParams): Promise<SearchResponse> {\n\tconst numResults = clampNumResults(params.num_results, DEFAULT_NUM_RESULTS, MAX_NUM_RESULTS);\n\tconst keyOrResolver: ApiKey = params.authStorage.resolver(\"jina\", {\n\t\tsessionId: params.sessionId,\n\t});\n\tconst response = await withAuth(\n\t\tkeyOrResolver,\n\t\tapiKey =>\n\t\t\tcallJinaSearch(apiKey, params.query, numResults, params.site, params.signal, params.fetch, params.timeoutMs),\n\t\t{\n\t\t\tsignal: params.signal,\n\t\t\tmissingKeyMessage: 'Jina credentials not found. Set JINA_API_KEY or configure an API key for provider \"jina\".',\n\t\t},","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/web/search/providers/jina.ts#L71-L107","documentation":"Thrown by callJinaSearch when the Jina response parsed as JSON is an object (or after the code check passes) but its `data` field is not an array. The provider's contract with Jina is that successful responses carry results in payload.data; anything else is treated as an uninterpretable response.","triggerScenarios":"Jina returns HTTP 200 with code 200 (or no code field) but `data` is missing, null, an object, or a string — e.g. a schema change on Jina's side or an unexpected empty-body success.","commonSituations":"Jina API version drift changing the response envelope; proxy/gateway replacing the body; malformed responses on partial outages.","solutions":["Log the raw response body to confirm the actual shape Jina returned","Check for Jina API changelog/version updates and update the JinaSearchResponse type if the schema changed","Check for intercepting proxies or gateways rewriting the response","Report/pin against a known-good Jina endpoint version"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"// validate shape defensively before consuming results\nconst res = await fetch(url); const body = await res.json();\nif (body && typeof body === 'object' && Array.isArray(body.data)) { /* safe */ }","typeGuard":"function hasDataArray(p: unknown): p is { data: unknown[] } {\n  return typeof p === 'object' && p !== null && Array.isArray((p as { data?: unknown }).data);\n}","tryCatchPattern":"try {\n  const res = await searchJina({ query, apiKey });\n} catch (err) {\n  if (err instanceof SearchProviderError && err.message.includes('expected data array')) {\n    logRawResponseForDiagnosis();\n    useFallbackProvider();\n  } else throw err;\n}","preventionTips":["Pin/monitor the Jina API version you depend on","Add a contract test asserting the response envelope shape","Route Jina traffic through a stable network path (no rewriting proxies)","Alert on unexpected response shapes in production"],"tags":["api","schema","response-parsing","jina"],"backgroundTag":"unexpected-response-schema","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}