{"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/5284672feb575908efead6fcf1b5e542f8d607bb/packages/sdk/src/commands/get-context/index.ts#L18-L50","documentation":"The get-context command's `exec` override throws `Context7Error` when `client.request()` returns no `result` for the `v1` context endpoint. With the default HttpClient the JSON body is wrapped as `{ result }`, so undefined results imply a broken custom transport or an empty/abnormal 200 response. Note the sibling hazard: a `txt` string is only honored when `responseType === 'txt'`; otherwise the code maps `codeSnippets`/`infoSnippets` off the result.","triggerScenarios":"A custom Requester resolving `{}`; a mock returning the payload without the `{ result }` envelope; an intermediary returning 200 with a JSON body the wrapper could not bind to `result`.","commonSituations":"Unit-testing GetContextCommand with hand-rolled fakes; swapping in an alternate HTTP transport that returns the raw body.","solutions":["Fix the Requester to resolve `{ result: body }`","In mocks, include the fields the code maps: `codeSnippets` and `infoSnippets` arrays","When requesting plain text, pass `type: 'txt'` so a string result is returned as-is"],"exampleFix":"// before\n{ request: async () => ({ result: undefined }) }\n\n// after\n{ request: async () => ({ result: { codeSnippets: [], infoSnippets: [] } }) }","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"function isApiContextJsonResponse(result: unknown): result is { codeSnippets: unknown[]; infoSnippets: unknown[] } {\n  return typeof result === 'object' && result !== null && Array.isArray((result as any).codeSnippets) && Array.isArray((result as any).infoSnippets);\n}","tryCatchPattern":"try {\n  return await cmd.exec(client);\n} catch (error) {\n  if (error instanceof Context7Error && /did not return a result/.test(error.message)) {\n    // envelope broken by a custom transport — inspect what request() resolved\n    throw new Error('empty result envelope from requester');\n  }\n  throw error;\n}","preventionTips":["Return the full `{ result }` envelope from custom transports and mocks","Request `type: 'txt'` when you want a plain string result","Ensure JSON-mode mocks include codeSnippets and infoSnippets arrays"],"tags":["sdk","documentation","invariant","typescript"],"backgroundTag":"empty-response-body","analyzedSha":"5284672feb575908efead6fcf1b5e542f8d607bb","analyzedAt":"2026-08-18T18:00:18.510Z","contentChangedAt":"2026-08-18T18:00:18.510Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}