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

  1. Validate/trim the query in the caller before invoking Search and skip the search when empty.
  2. Return a friendly 'empty query' response to the end user instead of performing the call.
  3. 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

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


AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02). Data as JSON: /api/errors/0eb55b4a229b4443. Report an issue: GitHub.