{"record":{"id":"7abc9ef31929f1ae","repo":"fish2018/pansou","slug":"s-w-7abc9e","errorCode":null,"errorMessage":"[%s] 编码搜索关键词失败: %w","messagePattern":"\\[(.+?)\\] 编码搜索关键词失败: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugin/dygang/dygang.go","lineNumber":168,"sourceCode":"\t\t\t\t\t}},\n\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\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 := \"tempid=1&tbname=article&keyboard=\" + url.QueryEscape(string(encoded)) + \"&show=title%2Csmalltext&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":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/fish2018/pansou/blob/beaa56133755a548ebc51b090b3816e2ae044aa6/plugin/dygang/dygang.go#L150-L186","documentation":"This error is thrown by DygangPlugin.fetchSearch when encodeGB18030 fails to convert the search keyword into GB18030 encoding. The dygang site expects search form fields encoded in GB18030 (Chinese encoding) rather than UTF-8, so keyword conversion is mandatory before building the POST form. The underlying encoder error is wrapped with the plugin name.","triggerScenarios":"Calling Search on the dygang plugin with a keyword whose text cannot be encoded to GB18030 (characters outside the GB18030 repertoire, or a malformed input encoding).","commonSituations":"Searching for titles containing rare Unicode symbols/emoji not representable in GB18030; input keyword arriving in a corrupt/mislabeled encoding; clipboard pasted text with invalid byte sequences.","solutions":["Sanitize the keyword: strip or transliterate characters not representable in GB18030 before searching","Retry with a simplified keyword (keep only common CJK and ASCII characters)","Check that the keyword input source is valid UTF-8 (validate/normalize with golang.org/x/text/encoding/unicode first)","If the site now accepts UTF-8, switch to encoding GB18030 only when needed"],"exampleFix":"// before\nencoded, err := encodeGB18030(keyword)\nif err != nil {\n    return nil, fmt.Errorf(\"[%s] 编码搜索关键词失败: %w\", p.Name(), err)\n}\n// after\ncleaned := sanitizeForGB18030(keyword) // drop chars outside GB18030 repertoire\nencoded, err := encodeGB18030(cleaned)\nif err != nil {\n    return nil, fmt.Errorf(\"[%s] 编码搜索关键词失败: %w\", p.Name(), err)\n}","handlingStrategy":"validation","validationCode":"if !utf8.ValidString(keyword) { keyword = strings.ToValidUTF8(keyword, \"\") }\nfor _, r := range keyword {\n    if !isGB18030Encodable(r) { return fmt.Errorf(\"non-GB18030 character: %q\", r) }\n}","typeGuard":null,"tryCatchPattern":"results, err := dygang.Search(keyword)\nif err != nil {\n    if strings.Contains(err.Error(), \"编码搜索关键词失败\") {\n        return dygang.Search(sanitizeForGB18030(keyword))\n    }\n    return err\n}","preventionTips":["Normalize keyword encodings at ingestion time","Keep a fallback path that retries with a cleaned keyword","Log the offending rune on encoding failure for quick diagnosis","Prefer plugins that accept UTF-8 when keyword sanitization is too lossy"],"tags":["encoding","gb18030","search","go"],"backgroundTag":"text-encoding-failed","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"}