upstash/context7 · error · Context7Error

Request did not return a result

Error message

Request did not return a result

What it means

`SearchLibraryCommand.exec` throws `Context7Error` when `client.request()` for `v2/libs/search` yields an undefined `result`. Like the other commands, the HttpClient wraps JSON bodies as `{ result: body }`, so this invariant guards against custom transports or mocks that drop the envelope; it also protects the subsequent `result.results.map(...)` from a null-deref.

Solutions

  1. Return the full envelope from your Requester: `{ result: { results: [...] } }`
  2. In mocks, always include a `results` array
  3. Log the raw response once to confirm what the transport actually resolved

Example fix

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

// after
{ request: async () => ({ result: { results: [{ id: '/r/react', name: 'react' }] } }) }
Defensive patterns

Strategy: type-guard

Type guard

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

Try / catch

try {
  return await searchCmd.exec(client);
} catch (error) {
  if (error instanceof Context7Error && /did not return a result/.test(error.message)) {
    throw new Error('search transport returned an empty envelope');
  }
  throw error;
}

Prevention

When it happens

Trigger: A custom Requester resolving `{}`; a test fake returning the API body directly instead of `{ result: { results: [...] } }`; an abnormal 200 response the wrapper could not bind.

Common situations: Mocking the search endpoint in unit tests; wrapping the Requester with logging/caching middleware that returns the wrong shape.

Related errors


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

Appendix: source

Thrown at packages/sdk/src/commands/search-library/index.ts:36

    const queryParams: Record<string, string | number | undefined> = {};

    queryParams.query = query;
    queryParams.libraryName = libraryName;

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

    this.responseType = options?.type ?? DEFAULT_TYPE;
  }

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

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

    const libraries = result.results.map(formatLibrary);

    if (this.responseType === "txt") {
      return formatLibrariesAsText(libraries);
    }

    return libraries;
  }
}

View on GitHub (pinned to 5284672feb)