{"record":{"id":"0eb55b4a229b4443","repo":"Tencent/WeKnora","slug":"query-is-empty-0eb55b","errorCode":null,"errorMessage":"query is empty","messagePattern":"query is empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/infrastructure/web_search/google.go","lineNumber":65,"sourceCode":"\t\tapiKey:   params.APIKey,\n\t\tengineID: params.EngineID,\n\t}, nil\n}\n\n// Name returns the provider name\nfunc (p *GoogleProvider) Name() string {\n\treturn \"google\"\n}\n\n// Search performs a web search using Google Custom Search Engine API\nfunc (p *GoogleProvider) Search(\n\tctx context.Context,\n\tquery string,\n\tmaxResults int,\n\tincludeDate bool,\n) ([]*types.WebSearchResult, error) {\n\tif len(query) == 0 {\n\t\treturn nil, fmt.Errorf(\"query is empty\")\n\t}\n\tlogger.Infof(ctx, \"[WebSearch][Google] query=%q maxResults=%d engineID=%s\", query, maxResults, p.engineID)\n\tcseCall := p.srv.Cse.List().Context(ctx).Cx(p.engineID).Q(query)\n\n\tif maxResults > 0 {\n\t\tcseCall = cseCall.Num(int64(maxResults))\n\t} else {\n\t\tcseCall = cseCall.Num(5)\n\t}\n\tcseCall = cseCall.Hl(\"ch-zh\")\n\n\tresp, err := cseCall.Do()\n\tif err != nil {\n\t\tlogger.Warnf(ctx, \"[WebSearch][Google] failed: %v\", err)\n\t\treturn nil, err\n\t}\n\tresults := make([]*types.WebSearchResult, 0)\n\tfor _, item := range resp.Items {","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/infrastructure/web_search/google.go#L47-L83","documentation":"GoogleProvider.Search rejects an empty query string before making any network call, returning this error. It is a client-side guard so no wasted Custom Search API quota is spent on a request that cannot return meaningful results.","triggerScenarios":"Calling p.Search(ctx, \"\", maxResults, includeDate) — empty string literal, or a query variable that was never populated / only whitespace stripped elsewhere.","commonSituations":"Upstream pipeline produced an empty user query; string trimming removed all content; a code path passes an unset variable; optional user input not defaulted before search.","solutions":["Validate/trim the query in the caller before invoking Search and skip the search when empty.","Return a friendly 'empty query' response to the end user instead of performing the call.","Trace where the query originates and fix the upstream producer that emits empty strings."],"exampleFix":"// before\nresults, err := googleProvider.Search(ctx, userQuery, 5, false)\n// after\nquery := strings.TrimSpace(userQuery)\nif query == \"\" {\n    return nil, nil // or a user-facing 'empty query' response\n}\nresults, err := googleProvider.Search(ctx, query, 5, false)","handlingStrategy":"validation","validationCode":"q := strings.TrimSpace(userQuery)\nif q == \"\" {\n    return nil, errors.New(\"cannot perform google search: empty query\")\n}\nreturn googleProvider.Search(ctx, q, maxResults, false)","typeGuard":null,"tryCatchPattern":"results, err := googleProvider.Search(ctx, q, n, false)\nif err != nil && err.Error() == \"query is empty\" {\n    return nil, errors.New(\"please provide search terms\")\n}","preventionTips":["Always trim and validate user input before search calls","Skip search flows entirely for empty queries instead of erroring","Add unit tests for empty-query paths in your integration layer","Normalize queries (collapse whitespace) before passing to providers"],"tags":["validation","google","web-search","input-validation"],"backgroundTag":"empty-required-parameter","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}