upstash/context7 · error · Context7Error

Request did not return a result

Error message

Request did not return a result

What it means

The get-context command's `exec` override throws `Context7Error` when `client.request()` returns no `result` for the `v1` context endpoint. With the default HttpClient the JSON body is wrapped as `{ result }`, so undefined results imply a broken custom transport or an empty/abnormal 200 response. Note the sibling hazard: a `txt` string is only honored when `responseType === 'txt'`; otherwise the code maps `codeSnippets`/`infoSnippets` off the result.

Solutions

  1. Fix the Requester to resolve `{ result: body }`
  2. In mocks, include the fields the code maps: `codeSnippets` and `infoSnippets` arrays
  3. When requesting plain text, pass `type: 'txt'` so a string result is returned as-is

Example fix

// before
{ request: async () => ({ result: undefined }) }

// after
{ request: async () => ({ result: { codeSnippets: [], infoSnippets: [] } }) }
Defensive patterns

Strategy: type-guard

Type guard

function isApiContextJsonResponse(result: unknown): result is { codeSnippets: unknown[]; infoSnippets: unknown[] } {
  return typeof result === 'object' && result !== null && Array.isArray((result as any).codeSnippets) && Array.isArray((result as any).infoSnippets);
}

Try / catch

try {
  return await cmd.exec(client);
} catch (error) {
  if (error instanceof Context7Error && /did not return a result/.test(error.message)) {
    // envelope broken by a custom transport — inspect what request() resolved
    throw new Error('empty result envelope from requester');
  }
  throw error;
}

Prevention

When it happens

Trigger: A custom Requester resolving `{}`; a mock returning the payload without the `{ result }` envelope; an intermediary returning 200 with a JSON body the wrapper could not bind to `result`.

Common situations: Unit-testing GetContextCommand with hand-rolled fakes; swapping in an alternate HTTP transport that returns the raw body.

Related errors


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

Appendix: source

Thrown at packages/sdk/src/commands/get-context/index.ts:36

    const responseType = options?.type ?? DEFAULT_TYPE;
    queryParams.type = responseType;

    super({ method: "GET", query: queryParams }, "v2/context");

    this.responseType = responseType;
  }

  public override async exec(client: Requester): Promise<Documentation[] | string> {
    const { result } = await client.request<string | ApiContextJsonResponse>({
      method: this.request.method || "GET",
      path: [this.endpoint],
      query: this.request.query,
      body: this.request.body,
    });

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

    if (this.responseType === "txt" && typeof result === "string") {
      return result;
    }

    const apiResult = result as ApiContextJsonResponse;
    const codeDocs = apiResult.codeSnippets.map(formatCodeSnippet);
    const infoDocs = apiResult.infoSnippets.map(formatInfoSnippet);

    return [...codeDocs, ...infoDocs];
  }
}

View on GitHub (pinned to 5284672feb)