Tencent/WeKnora · warning

query is empty

Error message

query is empty

What it means

KeenableProvider.Search guards against an empty query string and returns this error before issuing the HTTP POST. It mirrors the same guard as the Google provider so callers get a consistent, immediate failure instead of a meaningless remote search.

Source

Thrown at internal/infrastructure/web_search/keenable.go:68

		baseURL: defaultKeenableBaseURL,
		apiKey:  params.APIKey,
	}, nil
}

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

// Search performs a web search using the Keenable Search API.
func (p *KeenableProvider) Search(
	ctx context.Context,
	query string,
	maxResults int,
	includeDate bool,
) ([]*types.WebSearchResult, error) {
	if len(query) == 0 {
		return nil, fmt.Errorf("query is empty")
	}
	if maxResults <= 0 {
		maxResults = defaultKeenableResults
	}

	// Keyless by default; a configured key switches to the authenticated path.
	path := "/v1/search/public"
	if p.apiKey != "" {
		path = "/v1/search"
	}
	endpoint := p.baseURL + path
	logger.Infof(ctx, "[WebSearch][Keenable] query=%q maxResults=%d url=%s", query, maxResults, endpoint)

	bodyBytes, err := json.Marshal(keenableSearchRequest{Query: query, Mode: "pro"})
	if err != nil {
		return nil, fmt.Errorf("failed to marshal request: %w", err)
	}

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Trim and validate the query in the calling code before calling Search.
  2. Skip search flow entirely for empty queries and respond with a prompt for more input.
  3. Add a unit test covering the empty-query path of your integration layer.

Example fix

// before
results, err := keenable.Search(ctx, query, 10, false)
// after
query = strings.TrimSpace(query)
if query == "" {
    return nil, errors.New("cannot search: query is empty")
}
results, err := keenable.Search(ctx, query, 10, false)
Defensive patterns

Strategy: validation

Validate before calling

q := strings.TrimSpace(userQuery)
if q == "" {
    return nil, errors.New("cannot perform keenable search: empty query")
}
return keenable.Search(ctx, q, maxResults, false)

Try / catch

results, err := keenable.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 keenable.Search(ctx, "", maxResults, includeDate) — empty or never-populated query (tests TestKeenableProvider_Search_* exercise this path).

Common situations: Caller passes untrimmed user input that is empty; upstream NLU produced no terms; a variable defaulting to "" was forwarded directly.

Related errors


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