{"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/ca15df0443ee770506fc4eb270d1efc71d483933/packages/sdk/src/commands/command.ts#L16-L40","documentation":"Generic guard in the base Command.exec(): after client.request() returns, if `result` is undefined it throws a TypeError. This covers any command that does not override exec(). The HTTP layer normally always returns a result object (JSON body or text), so this firing indicates an unusual Requester implementation or an empty 2xx with a non-JSON content-type that parsed to undefined.","triggerScenarios":"A custom Requester whose request() resolves to { result: undefined }; a 200 response with no body and no JSON content-type where res.text() returned undefined; a mock/stub in tests that forgot to populate result.","commonSituations":"Unit tests with an incomplete mock Requester; a third-party Requester wrapper that strips the body; edge server response (200 with empty body) for an endpoint the SDK expected to return JSON.","solutions":["If using a custom Requester, ensure it returns { result: <parsed body> } for all success cases.","In tests, make the mock Requester resolve with a realistic result payload.","Check the actual response body and Content-Type with a raw HTTP call to see why it parsed as undefined.","Confirm the endpoint returns JSON (application/json) so the HTTP client populates result."],"exampleFix":"// before — mock Requester returns no result\nconst fakeClient = { request: async () => ({}) };\nawait cmd.exec(fakeClient as any); // throws TypeError\n\n// after\nconst fakeClient = { request: async () => ({ result: expectedPayload }) };\nawait cmd.exec(fakeClient as any);","handlingStrategy":"type-guard","validationCode":"// Ensure the Requester returns a defined result before exec() is called.\nasync function safeExec<T>(cmd: Command<T>, client: Requester): Promise<T> {\n  const res = await client.request<T>({ method: \"POST\", path: [cmd.endpoint] });\n  if (res.result === undefined) {\n    throw new Error(`Endpoint ${cmd.endpoint} returned an empty result — check the response body and Content-Type.`);\n  }\n  return res.result;\n}","typeGuard":"function hasResult<T>(v: unknown): v is { result: T } {\n  return typeof v === \"object\" && v !== null && (v as any).result !== undefined;\n}","tryCatchPattern":"try {\n  const out = await cmd.exec(client);\n} catch (e) {\n  if (e instanceof TypeError && /did not return a result/i.test(e.message)) {\n    // Defensive guard fired — usually an incomplete mock Requester or empty 2xx.\n    throw new Error(\"Empty response from SDK; verify the endpoint returns JSON and the Requester propagates it.\");\n  }\n  throw e;\n}","preventionTips":["Keep mock Requesters in tests faithful: always return { result: <body> }.","Confirm endpoints return application/json so the HTTP layer populates result.","Treat this TypeError as a canary for a broken Requester or empty 2xx, not a normal API error."],"tags":["sdk","http","type-guard","base-command"],"backgroundTag":null,"analyzedSha":"ca15df0443ee770506fc4eb270d1efc71d483933","analyzedAt":"2026-08-12T13:31:48.440Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}