{"record":{"id":"4ef8779ac4eb149f","repo":"Tencent/WeKnora","slug":"query-is-empty-4ef877","errorCode":null,"errorMessage":"query is empty","messagePattern":"query is empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/infrastructure/web_search/exa.go","lineNumber":67,"sourceCode":"\t\tbaseURL:     defaultExaSearchURL,\n\t\tapiKey:      apiKey,\n\t\tincludeText: parseExaBool(params.ExtraConfig, \"include_text\"),\n\t}, nil\n}\n\n// Name returns the provider type identifier.\nfunc (p *ExaProvider) Name() string { return \"exa\" }\n\n// Search performs a web search through Exa's official Search API.\nfunc (p *ExaProvider) Search(\n\tctx context.Context,\n\tquery string,\n\tmaxResults int,\n\tincludeDate bool,\n) ([]*types.WebSearchResult, error) {\n\tquery = strings.TrimSpace(query)\n\tif query == \"\" {\n\t\treturn nil, fmt.Errorf(\"query is empty\")\n\t}\n\tif maxResults <= 0 {\n\t\tmaxResults = defaultExaResults\n\t}\n\tif maxResults > maxExaResults {\n\t\tmaxResults = maxExaResults\n\t}\n\n\tbodyBytes, err := json.Marshal(exaSearchRequest{\n\t\tQuery:      query,\n\t\tNumResults: maxResults,\n\t\tContents: exaContents{\n\t\t\tHighlights: true,\n\t\t\tText:       p.includeText,\n\t\t},\n\t})\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to marshal Exa request: %w\", err)","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/infrastructure/web_search/exa.go#L49-L85","documentation":"Search validates its input and rejects an empty (after TrimSpace) query string. The provider requires a non-blank query to send to the Exa API, so blank input short-circuits with this error instead of wasting an API call.","triggerScenarios":"Calling Search with query \"\" or a whitespace-only string — e.g. user submitted an empty search box, upstream trimmed/parsed the query away, or a pipeline passed an unset variable.","commonSituations":"Frontend allowing empty search submissions, string extraction from documents yielding only whitespace, locale/encoding bugs stripping the query, passing an unbound variable from a template.","solutions":["Validate/trim the query in the caller before invoking Search and skip the call if empty","Return a user-facing 'please enter a search term' message for blank input","Check upstream string extraction for bugs that strip content","Guard pipeline steps so unset variables do not flow into Search"],"exampleFix":"// before\nresults, err := provider.Search(ctx, userQuery, 10, false)\n// after\nuserQuery = strings.TrimSpace(userQuery)\nif userQuery == \"\" {\n    return nil, ErrEmptyQuery\n}\nresults, err := provider.Search(ctx, userQuery, 10, false)","handlingStrategy":"validation","validationCode":"q := strings.TrimSpace(userQuery)\nif q == \"\" {\n    return nil, errors.New(\"search query must not be empty\")\n}","typeGuard":null,"tryCatchPattern":"results, err := provider.Search(ctx, userQuery, 10, false)\nif err != nil && strings.Contains(err.Error(), \"query is empty\") {\n    return nil, userFacingError(\"Please enter a search term.\")\n}","preventionTips":["Trim and validate user input at the API boundary before calling providers","Disable/validate empty search submissions in the frontend","Check text-extraction pipelines for whitespace-only outputs","Centralize query sanitization in one shared helper"],"tags":["validation","input","go"],"backgroundTag":"empty-query-parameter","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}