{"record":{"id":"e0633f722c8ff5b8","repo":"Tencent/WeKnora","slug":"query-is-empty-e0633f","errorCode":null,"errorMessage":"query is empty","messagePattern":"query is empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/infrastructure/web_search/zhipu.go","lineNumber":111,"sourceCode":"\t}\n\treturn searchEngine, contentSize\n}\n\n// Name returns the provider name.\nfunc (p *ZhipuProvider) Name() string {\n\treturn \"zhipu\"\n}\n\n// Search performs a web search using Zhipu AI's standalone Web Search API.\nfunc (p *ZhipuProvider) Search(\n\tctx context.Context,\n\tquery string,\n\tmaxResults int,\n\tincludeDate bool,\n) ([]*types.WebSearchResult, error) {\n\tpreparedQuery := normalizeZhipuQuery(query)\n\tif preparedQuery == \"\" {\n\t\treturn nil, fmt.Errorf(\"query is empty\")\n\t}\n\tif utf8.RuneCountInString(strings.TrimSpace(query)) > maxZhipuQueryRunes {\n\t\tlogger.Infof(ctx, \"[WebSearch][Zhipu] truncated query to %d characters\", maxZhipuQueryRunes)\n\t}\n\tif maxResults <= 0 {\n\t\tmaxResults = defaultZhipuResults\n\t}\n\tif maxResults > maxZhipuResults {\n\t\tmaxResults = maxZhipuResults\n\t}\n\n\trequestBody := zhipuSearchRequest{\n\t\tSearchQuery:  preparedQuery,\n\t\tSearchEngine: p.searchEngine,\n\t\tSearchIntent: false,\n\t\tCount:        maxResults,\n\t\tContentSize:  p.contentSize,\n\t}","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/infrastructure/web_search/zhipu.go#L93-L129","documentation":"Returned by ZhipuProvider.Search when normalizeZhipuQuery reduces the query to empty — the caller passed a blank/whitespace-only query that Zhipu's Web Search API would reject, so it fails fast before the network call.","triggerScenarios":"Calling provider.Search with an empty string, whitespace-only string, or a string that normalizes to empty (e.g. stripped whitespace/control chars) as the query.","commonSituations":"Upstream pipeline producing empty user messages, variables not interpolated in templates (\"\" template result), over-aggressive input sanitization stripping the query, or empty search boxes in UIs submitted without validation.","solutions":["Ensure callers pass a non-empty query","Skip the search when the extracted query is blank"],"exampleFix":"// before\nresults, err := provider.Search(ctx, userInput, 5, false)\n// after\nif strings.TrimSpace(userInput) == \"\" {\n    return nil, errors.New(\"search query must not be empty\")\n}\nresults, err := provider.Search(ctx, userInput, 5, false)","handlingStrategy":"validation","validationCode":"func ensureNonEmptyQuery(q string) error {\n    if strings.TrimSpace(q) == \"\" {\n        return errors.New(\"search query must not be empty\")\n    }\n    return nil\n}\n// call before provider.Search","typeGuard":null,"tryCatchPattern":"results, err := provider.Search(ctx, q, 5, false)\nif err != nil {\n    if strings.Contains(err.Error(), \"query is empty\") {\n        return fmt.Errorf(\"refusing empty search: provide a non-empty query (%w)\", err)\n    }\n    return err\n}","preventionTips":["Validate user input at the UI/API boundary before calling Search","Guard against empty template/variable substitution producing \"\"","Trim and check queries early in your request pipeline","Write a test asserting empty-query rejection"],"tags":["validation","input","zhipu","web-search"],"backgroundTag":"empty-query","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}