{"record":{"id":"db38180f471e1d7f","repo":"upstash/context7","slug":"request-did-not-return-a-result-db3818","errorCode":null,"errorMessage":"Request did not return a result","messagePattern":"Request did not return a result","errorType":"exception","errorClass":"Context7Error","httpStatus":null,"severity":"error","filePath":"packages/sdk/src/commands/get-context/index.ts","lineNumber":36,"sourceCode":"\n    const responseType = options?.type ?? DEFAULT_TYPE;\n    queryParams.type = responseType;\n\n    super({ method: \"GET\", query: queryParams }, \"v2/context\");\n\n    this.responseType = responseType;\n  }\n\n  public override async exec(client: Requester): Promise<Documentation[] | string> {\n    const { result } = await client.request<string | ApiContextJsonResponse>({\n      method: this.request.method || \"GET\",\n      path: [this.endpoint],\n      query: this.request.query,\n      body: this.request.body,\n    });\n\n    if (result === undefined) {\n      throw new Context7Error(\"Request did not return a result\");\n    }\n\n    if (this.responseType === \"txt\" && typeof result === \"string\") {\n      return result;\n    }\n\n    const apiResult = result as ApiContextJsonResponse;\n    const codeDocs = apiResult.codeSnippets.map(formatCodeSnippet);\n    const infoDocs = apiResult.infoSnippets.map(formatInfoSnippet);\n\n    return [...codeDocs, ...infoDocs];\n  }\n}\n","sourceCodeStart":18,"sourceCodeEnd":50,"githubUrl":"https://github.com/upstash/context7/blob/ca15df0443ee770506fc4eb270d1efc71d483933/packages/sdk/src/commands/get-context/index.ts#L18-L50","documentation":"Thrown by GetContextCommand.exec() (the override) when client.request() returns result === undefined. Same root cause as the base guard but throws Context7Error instead of TypeError, and applies specifically to the v2/context endpoint. After this check the code dereferences apiResult.codeSnippets / infoSnippets, so the guard prevents a downstream TypeError on undefined.","triggerScenarios":"GET v2/context returns 2xx but with an undefined body/result (empty body with non-JSON content-type, or a custom Requester returning { result: undefined }); a 204 No Content from a misconfigured gateway.","commonSituations":"Server bug returning 200 with empty body; proxy stripping the body; test mock missing the result field; wrong responseType configuration causing the HTTP layer to bypass JSON parsing.","solutions":["Reproduce the GET v2/context call directly and inspect status, Content-Type, and body.","In tests, make the mock Requester return a full ApiContextJsonResponse (with codeSnippets and infoSnippets arrays).","If the server genuinely returns empty, handle it upstream (return [] instead of throwing) — but only after confirming the contract.","Verify the endpoint URL and query params are well-formed so the server actually returns context."],"exampleFix":"// before\nconst mock = { request: async () => ({}) };\nawait cmd.exec(mock as any); // Context7Error\n\n// after\nconst mock = {\n  request: async () => ({\n    result: { codeSnippets: [], infoSnippets: [] },\n  }),\n};\nawait cmd.exec(mock as any); // -> []","handlingStrategy":"type-guard","validationCode":"import type { ApiContextJsonResponse } from \"./types\";\nfunction isContextResponse(v: unknown): v is ApiContextJsonResponse {\n  return (\n    typeof v === \"object\" && v !== null &&\n    Array.isArray((v as any).codeSnippets) &&\n    Array.isArray((v as any).infoSnippets)\n  );\n}\nconst res = await client.request<ApiContextJsonResponse>({ method: \"GET\", path: [\"v2/context\"], query });\nif (!isContextResponse(res.result)) {\n  throw new Error(\"v2/context did not return a JSON context body (missing codeSnippets/infoSnippets).\");\n}","typeGuard":"function isApiContextJsonResponse(v: unknown): v is { codeSnippets: unknown[]; infoSnippets: unknown[] } {\n  return typeof v === \"object\" && v !== null &&\n    Array.isArray((v as any).codeSnippets) && Array.isArray((v as any).infoSnippets);\n}","tryCatchPattern":"import { Context7Error } from \"@error\";\ntry {\n  const docs = await getContextCmd.exec(client);\n} catch (e) {\n  if (e instanceof Context7Error && /did not return a result/i.test(e.message)) {\n    throw new Error(\"v2/context returned an empty body — confirm the endpoint and responseType, then retry.\");\n  }\n  throw e;\n}","preventionTips":["In tests, have the mock Requester return a full ApiContextJsonResponse with both snippet arrays.","Confirm v2/context responses are application/json with a non-empty body.","Validate the response shape with isApiContextJsonResponse before dereferencing its fields."],"tags":["sdk","http","get-context","type-guard"],"backgroundTag":null,"analyzedSha":"ca15df0443ee770506fc4eb270d1efc71d483933","analyzedAt":"2026-08-12T13:31:48.440Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}