{"record":{"id":"744e4e104059fe4a","repo":"fish2018/pansou","slug":"s-w","errorCode":null,"errorMessage":"[%s] 编码搜索关键词失败: %w","messagePattern":"\\[(.+?)\\] 编码搜索关键词失败: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"plugin/5266ys/5266ys.go","lineNumber":169,"sourceCode":"\t\t\t\t}\n\t\t\t\tif imageURL != \"\" {\n\t\t\t\t\tresult.Images = []string{imageURL}\n\t\t\t\t}\n\t\t\t\tmu.Lock()\n\t\t\t\tresults = append(results, result)\n\t\t\t\tmu.Unlock()\n\t\t\t}\n\t\t}()\n\t}\n\twg.Wait()\n\n\treturn plugin.FilterResultsByKeyword(results, keyword), nil\n}\n\nfunc (p *Plugin) fetchSearch(client *http.Client, keyword string) (*goquery.Document, error) {\n\tencoded, err := encodeGB18030(keyword)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"[%s] 编码搜索关键词失败: %w\", p.Name(), err)\n\t}\n\tform := \"show=title%2Csmalltext&tempid=1&tbname=article&keyboard=\" + url.QueryEscape(string(encoded)) + \"&submit=\"\n\tctx, cancel := context.WithTimeout(context.Background(), requestTimeout)\n\tdefer cancel()\n\treq, err := http.NewRequestWithContext(ctx, http.MethodPost, baseURL+searchPath, strings.NewReader(form))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"[%s] 创建搜索请求失败: %w\", p.Name(), err)\n\t}\n\tsetHeaders(req, baseURL+\"/\")\n\treq.Header.Set(\"Content-Type\", \"application/x-www-form-urlencoded\")\n\tresp, err := client.Do(req)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"[%s] 搜索请求失败: %w\", p.Name(), err)\n\t}\n\tdefer resp.Body.Close()\n\tif resp.StatusCode != http.StatusOK {\n\t\treturn nil, fmt.Errorf(\"[%s] 搜索请求返回 HTTP %d\", p.Name(), resp.StatusCode)\n\t}","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/fish2018/pansou/blob/beaa56133755a548ebc51b090b3816e2ae044aa6/plugin/5266ys/5266ys.go#L151-L187","documentation":"fetchSearch wraps any failure from encodeGB18030 (converting the search keyword to GB18030 bytes, required because the target site uses that encoding) with this contextual error. It means the keyword could not be encoded for the site's GB18030 search form.","triggerScenarios":"Calling searchImpl -> fetchSearch with a keyword that encodeGB18030 cannot convert (unsupported runes / encoder failure) — typically exotic characters outside GB18030's coverage.","commonSituations":"Users searching with rare emoji or rare CJK-ext characters; keywords containing control characters; combining search terms copied from other apps.","solutions":["Sanitize the keyword before calling fetchSearch: strip or replace characters unsupported by GB18030","Fall back to UTF-8 encoding or URL-encoded raw keyword if GB18030 encoding fails","Update encodeGB18030 to use charmap/GB18030 encoder with replacement for unmapped runes","Log the offending keyword to identify which characters break encoding"],"exampleFix":"// before\nencoded, err := encodeGB18030(keyword)\nif err != nil {\n    return nil, fmt.Errorf(\"[%s] 编码搜索关键词失败: %w\", p.Name(), err)\n}\n// after\nencoded, err := encodeGB18030(keyword)\nif err != nil {\n    log.Warnf(\"[%s] GB18030 encode failed for %q, falling back to raw: %v\", p.Name(), keyword, err)\n    encoded = []byte(keyword)\n}","handlingStrategy":"fallback","validationCode":"// Go\nfor _, r := range keyword {\n    if r > 0x10FFFF || isControl(r) { return errors.New(\"keyword contains unsupported characters\") }\n}","typeGuard":null,"tryCatchPattern":"doc, err := p.fetchSearch(client, keyword)\nif err != nil && strings.Contains(err.Error(), \"编码搜索关键词失败\") {\n    // retry with sanitized keyword\n}","preventionTips":["Sanitize keywords: strip emoji/control chars before GB18030 encoding","Fall back to UTF-8/raw encoding when GB18030 fails","Log failing keywords to build a blocklist"],"tags":["encoding","gb18030","search","go"],"backgroundTag":"invalid-argument-format","analyzedSha":"beaa56133755a548ebc51b090b3816e2ae044aa6","analyzedAt":"2026-09-07T00:31:18.025Z","contentChangedAt":"2026-09-07T00:31:18.025Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}