{"record":{"id":"552df59946c8dc93","repo":"fish2018/pansou","slug":"s-w-552df5","errorCode":null,"errorMessage":"[%s] 解码搜索结果失败: %w","messagePattern":"\\[(.+?)\\] 解码搜索结果失败: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugin/5266ys/5266ys.go","lineNumber":194,"sourceCode":"\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}\n\tbody, err := io.ReadAll(io.LimitReader(resp.Body, 4<<20))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"[%s] 读取搜索结果失败: %w\", p.Name(), err)\n\t}\n\tdecoded, err := decodeGB18030(body)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"[%s] 解码搜索结果失败: %w\", p.Name(), err)\n\t}\n\tdoc, err := goquery.NewDocumentFromReader(strings.NewReader(decoded))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"[%s] 解析搜索结果失败: %w\", p.Name(), err)\n\t}\n\treturn doc, nil\n}\n\nfunc (p *Plugin) fetchDetail(client *http.Client, detailURL string) ([]magnetItem, string, string) {\n\tctx, cancel := context.WithTimeout(context.Background(), requestTimeout)\n\tdefer cancel()\n\treq, err := http.NewRequestWithContext(ctx, http.MethodGet, detailURL, nil)\n\tif err != nil {\n\t\treturn nil, \"\", \"\"\n\t}\n\tsetHeaders(req, baseURL+\"/\")\n\tresp, err := client.Do(req)\n\tif err != nil {","sourceCodeStart":176,"sourceCodeEnd":212,"githubUrl":"https://github.com/fish2018/pansou/blob/beaa56133755a548ebc51b090b3816e2ae044aa6/plugin/5266ys/5266ys.go#L176-L212","documentation":"fetchSearch wraps an error from decodeGB18030(body) — converting the site's GB18030-encoded HTML to UTF-8 failed. This is a plugin-local charset conversion; it fires only if the decode helper cannot transcode the bytes, typically because the payload is not actually GB18030 (e.g. a compressed, blank, or binary anti-bot page replaced the expected HTML).","triggerScenarios":"decodeGB18030 returns err: the response body is gzip/deflate-compressed but the request didn't request/accept decompression, the body is empty or binary garbage from a WAF challenge page, or the site switched to UTF-8 and the decoder rejects/produces invalid output (depending on the helper's implementation).","commonSituations":"Anti-bot returns an encoded challenge instead of HTML; Content-Encoding (gzip) is set but the body wasn't decompressed before decoding; the site silently migrated its encoding to UTF-8, breaking the assumed GB18030 input.","solutions":["Check the wrapped %w error to see what the decoder rejected, and dump the first bytes of body (hex) to confirm whether it's GB18030 HTML or a challenge/binary payload.","If Content-Encoding is gzip, ensure the transport decompresses (DisableCompression=false) or decompress before decoding.","Inspect the live page's charset meta tag with curl and update decodeGB18030 or use golang.org/x/net/html/charset auto-detection.","Handle an empty body explicitly before decoding to give a clearer message."],"exampleFix":"// before\ndecoded, err := decodeGB18030(body)\nif err != nil {\n    return nil, fmt.Errorf(\"[%s] 解码搜索结果失败: %w\", p.Name(), err)\n}\n// after\nif len(body) == 0 {\n    return nil, fmt.Errorf(\"[%s] 搜索结果为空\", p.Name())\n}\ndecoded, err := decodeGB18030(body)\nif err != nil {\n    return nil, fmt.Errorf(\"[%s] 解码搜索结果失败: %w\", p.Name(), err)\n}","handlingStrategy":"validation","validationCode":"// 解码前预检响应体\nif len(body) == 0 {\n    return fmt.Errorf(\"响应体为空\")\n}\nif ct := \"\"; resp.Header.Get(\"Content-Encoding\") == \"gzip\" {\n    return fmt.Errorf(\"响应未解压, 解码前需 gzip 解压\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Verify the site's actual charset (meta tag) with curl before assuming GB18030.","Ensure gzip/deflate responses are decompressed before charset decoding.","Handle empty or challenge-page bodies explicitly before decoding.","Prefer golang.org/x/net/html/charset auto-detection over hardcoded encodings."],"tags":["go","encoding","gb18030","scraping"],"backgroundTag":"charset-decode-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"}