{"record":{"id":"f3fbb2385df4dc03","repo":"upstash/context7","slug":"request-did-not-return-a-result","errorCode":null,"errorMessage":"Request did not return a result","messagePattern":"Request did not return a result","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/sdk/src/commands/command.ts","lineNumber":34,"sourceCode":"\n  constructor(request: CommandRequest, endpoint: EndpointVariants | string) {\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    const { result } = await client.request<TResult>({\n      method: this.request.method || \"POST\",\n      path: [this.endpoint],\n      query: this.request.query,\n      body: this.request.body,\n    });\n\n    if (result === undefined) {\n      throw new TypeError(\"Request did not return a result\");\n    }\n\n    return result;\n  }\n}\n","sourceCodeStart":16,"sourceCodeEnd":40,"githubUrl":"https://github.com/upstash/context7/blob/5284672feb575908efead6fcf1b5e542f8d607bb/packages/sdk/src/commands/command.ts#L16-L40","documentation":"Base `Command.exec` destructures `result` from `client.request()` and throws a `TypeError` when it is `undefined`. The SDK's own HttpClient always wraps JSON bodies as `{ result: body }`, so through the default transport this fires only in pathological cases (a custom Requester resolving without `result`). It is an invariant check, not a normal failure mode.","triggerScenarios":"Supplying a custom `Requester` implementation whose `request()` resolves `{}` or forgets the `result` field; a mock in tests returning the bare body instead of the `{ result }` envelope.","commonSituations":"Writing test fakes or alternate transports for the SDK; wrapping the Requester with middleware that drops the envelope.","solutions":["Make your Requester satisfy the contract: resolve `{ result: <body> }`","In tests, return the envelope: `{ result: mockedBody }` not the body itself","If it fires with the stock HttpClient, capture the raw response — the server sent something non-JSON-shaped"],"exampleFix":"// before (custom requester in tests)\nconst fake: Requester = { request: async () => ({ result: undefined }) };\n\n// after\nconst fake: Requester = { request: async () => ({ result: { docs: [] } }) };","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"function hasResult<T>(envelope: { result?: T }): envelope is { result: T } {\n  return envelope.result !== undefined;\n}","tryCatchPattern":"try {\n  return await command.exec(client);\n} catch (error) {\n  if (error instanceof TypeError && /did not return a result/.test(error.message)) {\n    throw new Error('transport broke the { result } envelope — fix the Requester');\n  }\n  throw error;\n}","preventionTips":["Keep custom Requesters faithful to the `{ result: body }` contract","Type mocks as Requester so shape drift is caught at compile time","Add one contract test asserting the transport resolves a defined result"],"tags":["sdk","typescript","invariant","requester"],"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"}