upstash/context7 · error · TypeError
Request did not return a result
Error message
Request did not return a result
What it means
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.
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 ca15df0443)
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.
Example fix
// before — mock Requester returns no result
const fakeClient = { request: async () => ({}) };
await cmd.exec(fakeClient as any); // throws TypeError
// after
const fakeClient = { request: async () => ({ result: expectedPayload }) };
await cmd.exec(fakeClient as any); Defensive patterns
Strategy: type-guard
Validate before calling
// Ensure the Requester returns a defined result before exec() is called.
async function safeExec<T>(cmd: Command<T>, client: Requester): Promise<T> {
const res = await client.request<T>({ method: "POST", path: [cmd.endpoint] });
if (res.result === undefined) {
throw new Error(`Endpoint ${cmd.endpoint} returned an empty result — check the response body and Content-Type.`);
}
return res.result;
} Type guard
function hasResult<T>(v: unknown): v is { result: T } {
return typeof v === "object" && v !== null && (v as any).result !== undefined;
} Try / catch
try {
const out = await cmd.exec(client);
} catch (e) {
if (e instanceof TypeError && /did not return a result/i.test(e.message)) {
// Defensive guard fired — usually an incomplete mock Requester or empty 2xx.
throw new Error("Empty response from SDK; verify the endpoint returns JSON and the Requester propagates it.");
}
throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Request did not return a result
- Request did not return a result
- errorBody.error || errorBody.message || res.statusText
- Failed to fetch user info
- ${fallback} (HTTP ${response.status} from ${response.url}):
AI-assisted analysis of upstash/context7@ca15df0443 (2026-08-12).
Data as JSON: /api/errors/f3fbb2385df4dc03.
Report an issue: GitHub.