upstash/context7 · error · Context7Error

invalid_response

invalid_response

Error message

Request did not return a result

What it means

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.

Source

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

  public readonly endpoint: EndpointVariants;

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

  /**
   * Execute the command using a client.
   */
  public async exec(client: Requester): Promise<TResult> {
    return this.requestResult<TResult>(client);
  }

  protected async requestResult<T>(client: Requester): Promise<T> {
    const { result } = await client.request<T>({ ...this.request, path: [this.endpoint] });

    if (result === undefined) {
      throw new Context7Error("Request did not return a result", {
        code: "invalid_response",
      });
    }

    return result;
  }
}

View on GitHub (pinned to 80e681a507)

Solutions

  1. Inspect the raw HTTP response (status 200 body) to see what the server actually returned; it likely isn't the expected { result } envelope.
  2. Verify the Context7 server/API version matches the SDK version; upgrade or downgrade so the response contract matches.
  3. Check for proxies, mocks, or custom fetch/onResponse handlers that mutate or replace the response body.
  4. Wrap command execution in try-catch for Context7Error and check err.code === 'invalid_response' to add diagnostics or fallback.

Example fix

// before
const data = await client.exec(cmd); // throws: Request did not return a result
// after
try {
  const data = await client.exec(cmd);
} catch (e) {
  if (e instanceof Context7Error && e.code === 'invalid_response') {
    console.error('Server response missing result field; check server version/proxy', e);
  }
  throw e;
}
Defensive patterns

Strategy: try-catch

Validate before calling

// Best-effort: nothing to check before the call; validate server reachability/version instead.
assert(typeof process.env.CONTEXT7_BASE_URL === 'string' && process.env.CONTEXT7_BASE_URL.length > 0);

Type guard

function isContext7InvalidResponse(e: unknown): e is Context7Error {
  return e instanceof Context7Error && e.code === 'invalid_response';
}

Try / catch

try {
  const data = await client.exec(cmd);
} catch (e) {
  if (isContext7InvalidResponse(e)) {
    // log raw response, alert on protocol mismatch, or fall back
    return fallbackValue;
  }
  throw e;
}

Prevention

When it happens

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

Common situations: 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.

Understand the failure class

Background: "invalid response format", "malformed payload", "missing data field": when an API returns 200 but the response shape is wrong — this error's family across 23 libraries.

Related errors


AI-assisted analysis of upstash/context7@80e681a507 (2026-09-08). Data as JSON: /api/errors/fd24fc5546e03c93. Report an issue: GitHub.