{"record":{"id":"d38611759f05da8d","repo":"upstash/context7","slug":"request-did-not-return-a-result-d38611","errorCode":null,"errorMessage":"Request did not return a result","messagePattern":"Request did not return a result","errorType":"exception","errorClass":"Context7Error","httpStatus":null,"severity":"error","filePath":"packages/sdk/src/commands/search-library/index.ts","lineNumber":36,"sourceCode":"    const queryParams: Record<string, string | number | undefined> = {};\n\n    queryParams.query = query;\n    queryParams.libraryName = libraryName;\n\n    super({ method: \"GET\", query: queryParams }, \"v2/libs/search\");\n\n    this.responseType = options?.type ?? DEFAULT_TYPE;\n  }\n\n  public override async exec(client: Requester): Promise<Library[] | string> {\n    const { result } = await client.request<ApiSearchResponse>({\n      method: this.request.method || \"GET\",\n      path: [this.endpoint],\n      query: this.request.query,\n    });\n\n    if (result === undefined) {\n      throw new Context7Error(\"Request did not return a result\");\n    }\n\n    const libraries = result.results.map(formatLibrary);\n\n    if (this.responseType === \"txt\") {\n      return formatLibrariesAsText(libraries);\n    }\n\n    return libraries;\n  }\n}\n","sourceCodeStart":18,"sourceCodeEnd":48,"githubUrl":"https://github.com/upstash/context7/blob/5284672feb575908efead6fcf1b5e542f8d607bb/packages/sdk/src/commands/search-library/index.ts#L18-L48","documentation":"`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.","triggerScenarios":"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.","commonSituations":"Mocking the search endpoint in unit tests; wrapping the Requester with logging/caching middleware that returns the wrong shape.","solutions":["Return the full envelope from your Requester: `{ result: { results: [...] } }`","In mocks, always include a `results` array","Log the raw response once to confirm what the transport actually resolved"],"exampleFix":"// before\n{ request: async () => ({ result: undefined }) }\n\n// after\n{ request: async () => ({ result: { results: [{ id: '/r/react', name: 'react' }] } }) }","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"function isApiSearchResponse(result: unknown): result is { results: unknown[] } {\n  return typeof result === 'object' && result !== null && Array.isArray((result as any).results);\n}","tryCatchPattern":"try {\n  return await searchCmd.exec(client);\n} catch (error) {\n  if (error instanceof Context7Error && /did not return a result/.test(error.message)) {\n    throw new Error('search transport returned an empty envelope');\n  }\n  throw error;\n}","preventionTips":["Mock `{ result: { results: [...] } }`, never the bare body","Keep middleware around Requester envelope-preserving","Add a contract test pinning the response envelope shape"],"tags":["sdk","search","invariant","typescript"],"backgroundTag":"empty-response-body","analyzedSha":"5284672feb575908efead6fcf1b5e542f8d607bb","analyzedAt":"2026-08-18T18:00:18.510Z","contentChangedAt":"2026-08-18T18:00:18.510Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}