{"record":{"id":"37dc611b82cf62b5","repo":"Tencent/WeKnora","slug":"query-is-empty-37dc61","errorCode":null,"errorMessage":"query is empty","messagePattern":"query is empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/infrastructure/web_search/metaso.go","lineNumber":77,"sourceCode":"\tif _, ok := validMetasoScopes[scope]; !ok {\n\t\treturn fmt.Errorf(\"invalid Metaso search scope: %s\", scope)\n\t}\n\treturn nil\n}\n\nfunc metasoScope(extraConfig map[string]string) string {\n\tif scope := strings.TrimSpace(extraConfig[\"scope\"]); scope != \"\" {\n\t\treturn scope\n\t}\n\treturn defaultMetasoScope\n}\n\nfunc (p *MetasoProvider) Name() string { return \"metaso\" }\n\nfunc (p *MetasoProvider) Search(ctx context.Context, query string, maxResults int, includeDate bool) ([]*types.WebSearchResult, error) {\n\tquery = strings.TrimSpace(query)\n\tif query == \"\" {\n\t\treturn nil, fmt.Errorf(\"query is empty\")\n\t}\n\tif maxResults <= 0 {\n\t\tmaxResults = defaultMetasoResults\n\t}\n\tif maxResults > maxMetasoResults {\n\t\tmaxResults = maxMetasoResults\n\t}\n\n\tbody, err := json.Marshal(metasoSearchRequest{\n\t\tQuery: query, Scope: p.scope, Size: maxResults,\n\t\tIncludeSummary: true, IncludeRawContent: false, ConciseSnippet: true,\n\t})\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to marshal Metaso request: %w\", err)\n\t}\n\treq, err := http.NewRequestWithContext(ctx, http.MethodPost, p.baseURL, bytes.NewReader(body))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create Metaso request: %w\", err)","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/infrastructure/web_search/metaso.go#L59-L95","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nresults, err := provider.Search(ctx, userInput, 10, false)\n\n// after\nq := strings.TrimSpace(userInput)\nif q == \"\" {\n    return nil, fmt.Errorf(\"search query must not be empty\")\n}\nresults, err := provider.Search(ctx, q, 10, false)","handlingStrategy":"validation","validationCode":"func validateQuery(q string) (string, error) {\n    q = strings.TrimSpace(q)\n    if q == \"\" {\n        return \"\", fmt.Errorf(\"search query must not be empty\")\n    }\n    return q, nil\n}\n\nq, err := validateQuery(userInput)\nif err != nil { return err }","typeGuard":null,"tryCatchPattern":"results, err := provider.Search(ctx, userInput, 10, false)\nif err != nil {\n    if err.Error() == \"query is empty\" {\n        return nil, ErrEmptySearchQuery // typed sentinel for callers to handle as user error\n    }\n    return nil, err\n}","preventionTips":["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."],"tags":["validation","input","web-search"],"backgroundTag":"empty-required-parameter","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}