Tencent/WeKnora · warning
query is empty
Error message
query is empty
What it means
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.
Source
Thrown at internal/infrastructure/web_search/google.go:65
apiKey: params.APIKey,
engineID: params.EngineID,
}, nil
}
// Name returns the provider name
func (p *GoogleProvider) Name() string {
return "google"
}
// Search performs a web search using Google Custom Search Engine API
func (p *GoogleProvider) Search(
ctx context.Context,
query string,
maxResults int,
includeDate bool,
) ([]*types.WebSearchResult, error) {
if len(query) == 0 {
return nil, fmt.Errorf("query is empty")
}
logger.Infof(ctx, "[WebSearch][Google] query=%q maxResults=%d engineID=%s", query, maxResults, p.engineID)
cseCall := p.srv.Cse.List().Context(ctx).Cx(p.engineID).Q(query)
if maxResults > 0 {
cseCall = cseCall.Num(int64(maxResults))
} else {
cseCall = cseCall.Num(5)
}
cseCall = cseCall.Hl("ch-zh")
resp, err := cseCall.Do()
if err != nil {
logger.Warnf(ctx, "[WebSearch][Google] failed: %v", err)
return nil, err
}
results := make([]*types.WebSearchResult, 0)
for _, item := range resp.Items {View on GitHub (pinned to 988cbb0330)
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.
Example fix
// before
results, err := googleProvider.Search(ctx, userQuery, 5, false)
// after
query := strings.TrimSpace(userQuery)
if query == "" {
return nil, nil // or a user-facing 'empty query' response
}
results, err := googleProvider.Search(ctx, query, 5, false) Defensive patterns
Strategy: validation
Validate before calling
q := strings.TrimSpace(userQuery)
if q == "" {
return nil, errors.New("cannot perform google search: empty query")
}
return googleProvider.Search(ctx, q, maxResults, false) Try / catch
results, err := googleProvider.Search(ctx, q, n, false)
if err != nil && err.Error() == "query is empty" {
return nil, errors.New("please provide search terms")
} Prevention
- 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
When it happens
Trigger: Calling p.Search(ctx, "", maxResults, includeDate) — empty string literal, or a query variable that was never populated / only whitespace stripped elsewhere.
Common situations: 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.
Related errors
- query is empty
- member_limit must be >= 0
- API key is required for Ollama provider
- API key is required for Baidu provider
- API key is required for Exa provider
AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02).
Data as JSON: /api/errors/0eb55b4a229b4443.
Report an issue: GitHub.