{"record":{"id":"59fa235babbd4dd1","repo":"mastra-ai/mastra","slug":"search-query-is-required","errorCode":null,"errorMessage":"Search query is required","messagePattern":"Search query is required","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"warning","filePath":"packages/server/src/server/handlers/workspace.ts","lineNumber":770,"sourceCode":"// Search Routes\n// =============================================================================\n\nexport const WORKSPACE_SEARCH_ROUTE = createRoute({\n  method: 'GET',\n  path: '/workspaces/:workspaceId/search',\n  responseType: 'json',\n  pathParamSchema: workspaceIdPathParams,\n  queryParamSchema: searchQuerySchema,\n  responseSchema: searchResponseSchema,\n  summary: 'Search workspace content',\n  description: 'Searches across indexed workspace content using BM25, vector, or hybrid search',\n  tags: ['Workspace'],\n  handler: async ({ mastra, query, topK, mode, minScore, workspaceId }) => {\n    try {\n      requireWorkspaceV1Support();\n\n      if (!query) {\n        throw new HTTPException(400, { message: 'Search query is required' });\n      }\n\n      const workspace = await getWorkspaceById(mastra, workspaceId);\n      if (!workspace) {\n        return {\n          results: [],\n          query,\n          mode: mode || 'bm25',\n        };\n      }\n\n      // Check search capabilities\n      const canSearch = workspace.canBM25 || workspace.canVector;\n      if (!canSearch) {\n        return {\n          results: [],\n          query,\n          mode: mode || 'bm25',","sourceCodeStart":752,"sourceCodeEnd":788,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/server/src/server/handlers/workspace.ts#L752-L788","documentation":"The workspace search handler (GET /api/workspaces/:workspaceId/search) throws this 400 when the `query` parameter is missing or empty. Search requires a non-empty query string to pass to workspace.search(). This is a request-validation guard before any workspace lookup occurs.","triggerScenarios":"Calling GET /workspaces/:workspaceId/search without a `query` query parameter, with `?query=` (empty string), or with a client that strips empty query params — e.g. building the URL conditionally and omitting query when the user's search box is empty.","commonSituations":"UI sending the search request before the user types anything; a template-literal URL with an undefined variable; HTTP clients that drop null/undefined params; wrappers around the Mastra client with default-empty arguments.","solutions":["Include a non-empty `query` query parameter in the request.","In the UI, disable or skip the search request until input is non-empty.","If a blank search should return all/no results, handle that client-side instead of calling the endpoint."],"exampleFix":"// before\nconst url = `/api/workspaces/ws1/search?topK=5`;\n// after\nconst url = `/api/workspaces/ws1/search?query=${encodeURIComponent(term)}&topK=5`;","handlingStrategy":"validation","validationCode":"if (typeof query !== 'string' || query.trim() === '') {\n  throw new Error('query is required before calling workspace search');\n}","typeGuard":"function hasQuery(q: unknown): q is string {\n  return typeof q === 'string' && q.trim().length > 0;\n}","tryCatchPattern":"try {\n  const results = await searchWorkspace(wsId, query);\n} catch (e) {\n  if (isHTTPException(e, 400) && e.message === 'Search query is required') {\n    return { results: [], query: '' }; // degrade gracefully for empty input\n  }\n  throw e;\n}","preventionTips":["Disable search submission until input is non-empty","Build URLs with a params helper that validates required params","Add client-side unit tests for empty-query behavior","Never rely on undefined interpolation in query strings"],"tags":["http-400","validation","search","missing-parameter"],"backgroundTag":"missing-required-parameter","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}