upstash/context7 · error · TypeError

Request did not return a result

Error message

Request did not return a result

What it means

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.

Solutions

  1. Make your Requester satisfy the contract: resolve `{ result: <body> }`
  2. In tests, return the envelope: `{ result: mockedBody }` not the body itself
  3. If it fires with the stock HttpClient, capture the raw response — the server sent something non-JSON-shaped

Example fix

// before (custom requester in tests)
const fake: Requester = { request: async () => ({ result: undefined }) };

// after
const fake: Requester = { request: async () => ({ result: { docs: [] } }) };
Defensive patterns

Strategy: type-guard

Type guard

function hasResult<T>(envelope: { result?: T }): envelope is { result: T } {
  return envelope.result !== undefined;
}

Try / catch

try {
  return await command.exec(client);
} catch (error) {
  if (error instanceof TypeError && /did not return a result/.test(error.message)) {
    throw new Error('transport broke the { result } envelope — fix the Requester');
  }
  throw error;
}

Prevention

When it happens

Trigger: 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.

Common situations: Writing test fakes or alternate transports for the SDK; wrapping the Requester with middleware that drops the envelope.

Related errors


AI-assisted analysis of upstash/context7@5284672feb (2026-08-18). Data as JSON: /api/errors/f3fbb2385df4dc03. Report an issue: GitHub.

Appendix: source

Thrown at packages/sdk/src/commands/command.ts:34

  constructor(request: CommandRequest, endpoint: EndpointVariants | string) {
    this.request = request;
    this.endpoint = endpoint;
  }

  /**
   * Execute the command using a client.
   */
  public async exec(client: Requester): Promise<TResult> {
    const { result } = await client.request<TResult>({
      method: this.request.method || "POST",
      path: [this.endpoint],
      query: this.request.query,
      body: this.request.body,
    });

    if (result === undefined) {
      throw new TypeError("Request did not return a result");
    }

    return result;
  }
}

View on GitHub (pinned to 5284672feb)