Tencent/WeKnora · error

query is empty

Error message

query is empty

What it means

The Bing web search provider rejects a Search call whose query string is empty (len(query) == 0) at the very start of the method, before any network or configuration work. It is a defensive guard so the provider never issues a meaningless API request. The error is created with fmt.Errorf and carries no wrapping.

Source

Thrown at internal/infrastructure/web_search/bing.go:81

		baseURL: defaultBingSearchURL, // Hardcoded — not tenant-configurable
		apiKey:  params.APIKey,
	}, nil
}

// Name returns the provider name
func (p *BingProvider) Name() string {
	return "bing"
}

// Search performs a web search using Bing Search API
func (p *BingProvider) 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][Bing] query=%q maxResults=%d url=%s", query, maxResults, p.baseURL)
	req, err := p.buildParams(ctx, query, maxResults, includeDate)
	if err != nil {
		return nil, err
	}
	results, err := p.doSearch(ctx, req)
	if err != nil {
		logger.Warnf(ctx, "[WebSearch][Bing] failed: %v", err)
		return nil, err
	}
	logger.Infof(ctx, "[WebSearch][Bing] returned %d results", len(results))
	return results, nil
}

func (p *BingProvider) doSearch(ctx context.Context, req *http.Request) ([]*types.WebSearchResult, error) {
	resp, err := p.client.Do(req)
	if err != nil {

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Validate the query in the caller before invoking Search: if strings.TrimSpace(query) == "" { return error/early exit }.
  2. Trace where the query originates (user input, config, upstream function) and fix the producer so it never yields an empty string.
  3. If empty queries are legitimate, return a friendly 'please provide a search term' message to the user instead of calling the provider.

Example fix

// before
results, err := provider.Search(ctx, userQuery, 10, false)
// after
userQuery = strings.TrimSpace(userQuery)
if userQuery == "" {
    return nil, errors.New("search term is required")
}
results, err := provider.Search(ctx, userQuery, 10, false)
Defensive patterns

Strategy: validation

Validate before calling

if strings.TrimSpace(query) == "" {
    return nil, errors.New("search query must not be empty")
}
results, err := provider.Search(ctx, query, maxResults, includeDate)

Type guard

func hasQuery(q string) bool { return strings.TrimSpace(q) != "" }

Prevention

When it happens

Trigger: Calling bingProvider.Search(ctx, "", maxResults, includeDate) with a zero-length query string, or passing a query variable that was never populated by an upstream step (empty user input, failed extraction).

Common situations: User submits a blank search box; a pipeline stage strips characters (e.g. trimming punctuation) leaving an empty string; a caller forwards a query field from an unvalidated struct.

Related errors


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