{"record":{"id":"fd24fc5546e03c93","repo":"upstash/context7","slug":"invalid-response","errorCode":"invalid_response","errorMessage":"Request did not return a result","messagePattern":"Request did not return a result","errorType":"error_code","errorClass":"Context7Error","httpStatus":null,"severity":"error","filePath":"packages/sdk/src/commands/command.ts","lineNumber":30,"sourceCode":"  public readonly endpoint: EndpointVariants;\n\n  constructor(request: CommandRequest, endpoint: EndpointVariants) {\n    this.request = request;\n    this.endpoint = endpoint;\n  }\n\n  /**\n   * Execute the command using a client.\n   */\n  public async exec(client: Requester): Promise<TResult> {\n    return this.requestResult<TResult>(client);\n  }\n\n  protected async requestResult<T>(client: Requester): Promise<T> {\n    const { result } = await client.request<T>({ ...this.request, path: [this.endpoint] });\n\n    if (result === undefined) {\n      throw new Context7Error(\"Request did not return a result\", {\n        code: \"invalid_response\",\n      });\n    }\n\n    return result;\n  }\n}\n","sourceCodeStart":12,"sourceCodeEnd":38,"githubUrl":"https://github.com/upstash/context7/blob/80e681a507c5287bc12e483367c40754e29461b9/packages/sdk/src/commands/command.ts#L12-L38","documentation":"Context7Error with code \"invalid_response\", thrown by Command.requestResult when the HTTP response body parsed successfully but contained no `result` field (it was undefined). The SDK treats every command response as a JSON envelope like { result: ... }; a missing result means the server reply did not match the expected protocol shape.","triggerScenarios":"Executing any Context7 command (e.g. via client.exec/command) when the server returns a 2xx response whose JSON body lacks a top-level `result` property, such as {\"error\":...} with 200, an empty body, or an unexpected API version response shape.","commonSituations":"Proxy/gateway returning a 200 with an empty or different-shaped body, a mock server or stub returning {}, an incompatible Context7 server version, or an interceptor stripping fields from the response.","solutions":["Inspect the raw HTTP response (status 200 body) to see what the server actually returned; it likely isn't the expected { result } envelope.","Verify the Context7 server/API version matches the SDK version; upgrade or downgrade so the response contract matches.","Check for proxies, mocks, or custom fetch/onResponse handlers that mutate or replace the response body.","Wrap command execution in try-catch for Context7Error and check err.code === 'invalid_response' to add diagnostics or fallback."],"exampleFix":"// before\nconst data = await client.exec(cmd); // throws: Request did not return a result\n// after\ntry {\n  const data = await client.exec(cmd);\n} catch (e) {\n  if (e instanceof Context7Error && e.code === 'invalid_response') {\n    console.error('Server response missing result field; check server version/proxy', e);\n  }\n  throw e;\n}","handlingStrategy":"try-catch","validationCode":"// Best-effort: nothing to check before the call; validate server reachability/version instead.\nassert(typeof process.env.CONTEXT7_BASE_URL === 'string' && process.env.CONTEXT7_BASE_URL.length > 0);","typeGuard":"function isContext7InvalidResponse(e: unknown): e is Context7Error {\n  return e instanceof Context7Error && e.code === 'invalid_response';\n}","tryCatchPattern":"try {\n  const data = await client.exec(cmd);\n} catch (e) {\n  if (isContext7InvalidResponse(e)) {\n    // log raw response, alert on protocol mismatch, or fall back\n    return fallbackValue;\n  }\n  throw e;\n}","preventionTips":["Pin matching SDK and server/API versions.","Avoid proxies/mocks that rewrite 2xx response bodies in production paths.","Add contract tests asserting responses contain a result field.","Log the raw response body on this error to speed diagnosis."],"tags":["invalid-response","api-protocol","http"],"backgroundTag":"unexpected-api-response-shape","analyzedSha":"80e681a507c5287bc12e483367c40754e29461b9","analyzedAt":"2026-09-08T05:18:41.043Z","contentChangedAt":"2026-09-08T05:18:41.043Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}