Tencent/WeKnora · warning
query is empty
Error message
query is empty
What it means
Returned by MetasoProvider.Search when the query argument is empty or contains only whitespace after strings.TrimSpace. Metaso (like most search APIs) rejects empty queries, so the provider validates the input before issuing an HTTP request. It is a pure input-validation error, not a network problem.
Source
Thrown at internal/infrastructure/web_search/metaso.go:77
if _, ok := validMetasoScopes[scope]; !ok {
return fmt.Errorf("invalid Metaso search scope: %s", scope)
}
return nil
}
func metasoScope(extraConfig map[string]string) string {
if scope := strings.TrimSpace(extraConfig["scope"]); scope != "" {
return scope
}
return defaultMetasoScope
}
func (p *MetasoProvider) Name() string { return "metaso" }
func (p *MetasoProvider) Search(ctx context.Context, query string, maxResults int, includeDate bool) ([]*types.WebSearchResult, error) {
query = strings.TrimSpace(query)
if query == "" {
return nil, fmt.Errorf("query is empty")
}
if maxResults <= 0 {
maxResults = defaultMetasoResults
}
if maxResults > maxMetasoResults {
maxResults = maxMetasoResults
}
body, err := json.Marshal(metasoSearchRequest{
Query: query, Scope: p.scope, Size: maxResults,
IncludeSummary: true, IncludeRawContent: false, ConciseSnippet: true,
})
if err != nil {
return nil, fmt.Errorf("failed to marshal Metaso request: %w", err)
}
req, err := http.NewRequestWithContext(ctx, http.MethodPost, p.baseURL, bytes.NewReader(body))
if err != nil {
return nil, fmt.Errorf("failed to create Metaso request: %w", err)View on GitHub (pinned to 988cbb0330)
Solutions
- Check the query for emptiness at the call site before invoking Search and return a user-friendly 'please enter a search term' result.
- Trace where the query originates (UI field, LLM-extracted term) and fix the source producing empty strings.
- Trim and validate user input at the boundary of your application.
- In tests/automation, always pass a non-empty query fixture.
Example fix
// before
results, err := provider.Search(ctx, userInput, 10, false)
// after
q := strings.TrimSpace(userInput)
if q == "" {
return nil, fmt.Errorf("search query must not be empty")
}
results, err := provider.Search(ctx, q, 10, false) Defensive patterns
Strategy: validation
Validate before calling
func validateQuery(q string) (string, error) {
q = strings.TrimSpace(q)
if q == "" {
return "", fmt.Errorf("search query must not be empty")
}
return q, nil
}
q, err := validateQuery(userInput)
if err != nil { return err } Try / catch
results, err := provider.Search(ctx, userInput, 10, false)
if err != nil {
if err.Error() == "query is empty" {
return nil, ErrEmptySearchQuery // typed sentinel for callers to handle as user error
}
return nil, err
} Prevention
- Trim and reject empty input at the UI/API boundary before it reaches providers.
- Ensure empty search submissions short-circuit to a friendly no-op result.
- In pipelines, assert query extraction produced a non-empty term before calling Search.
- Use a typed sentinel error or custom error type so empty-query can be distinguished from network failures.
When it happens
Trigger: MetasoProvider.Search (internal/infrastructure/web_search/metaso.go:77) called with query="" or query=" " — e.g. user submitted an empty search box, an upstream pipeline stripped the query, or a caller passed an uninitialized string.
Common situations: Empty search input from UI forwarded verbatim; chat pipeline where query extraction produced an empty string; TrimSpace removed a whitespace-only placeholder; test harness passing no query.
Related errors
- query is empty
- query is empty
- invalid file name: %w
- API key is required for Ollama provider
- API key is required for Baidu provider
AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02).
Data as JSON: /api/errors/37dc611b82cf62b5.
Report an issue: GitHub.