{"record":{"id":"d7380ae349c2e17d","repo":"fish2018/pansou","slug":"s-w-d7380a","errorCode":null,"errorMessage":"[%s] 解码搜索结果失败: %w","messagePattern":"\\[(.+?)\\] 解码搜索结果失败: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugin/dygang/dygang.go","lineNumber":193,"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":175,"sourceCodeEnd":211,"githubUrl":"https://github.com/fish2018/pansou/blob/beaa56133755a548ebc51b090b3816e2ae044aa6/plugin/dygang/dygang.go#L175-L211","documentation":"The raw response bytes could not be converted from GB18030 to UTF-8 by decodeGB18030, so the plugin cannot proceed to HTML parsing. This means the body is not valid GB18030 — typically because the site changed its encoding (e.g. now serving UTF-8) or returned compressed/binary/garbage content. The wrapped error comes from the GB18030 decoder (golang.org/x/text).","triggerScenarios":"decodeGB18030(body) errors in fetchSearch: body bytes are not decodable as GB18030 — the site switched to UTF-8, the response is gzip/deflate that was not decompressed, or a CAPTCHA/binary page was returned instead of HTML.","commonSituations":"Target site migrated to UTF-8 while the plugin still assumes GB18030; a reverse proxy or CDN serving compressed content without the plugin requesting/handling it; an HTML error or challenge page with bytes the decoder rejects.","solutions":["Check the response's Content-Type charset and <meta charset> to confirm the actual encoding; update decodeGB18030 usage if the site switched to UTF-8.","Ensure gzip handling: set Accept-Encoding explicitly or wrap resp.Body with gzip.NewReader when Content-Encoding is gzip.","Inspect the first bytes of the body (hex dump) to detect compressed or binary content.","Fall back to decoding as UTF-8 when GB18030 decoding fails."],"exampleFix":"// before\ndecoded, err := decodeGB18030(body)\nif err != nil {\n\treturn nil, fmt.Errorf(\"[%s] 解码搜索结果失败: %w\", p.Name(), err)\n}\n// after\ndecoded, err := decodeGB18030(body)\nif err != nil {\n\tif utf8.Valid(body) {\n\t\tdecoded = string(body) // site switched to UTF-8\n\t} else {\n\t\treturn nil, fmt.Errorf(\"[%s] 解码搜索结果失败: %w\", p.Name(), err)\n\t}\n}","handlingStrategy":"fallback","validationCode":"if !utf8.Valid(body) && !looksLikeGB18030(body) {\n\treturn fmt.Errorf(\"body is neither valid UTF-8 nor GB18030\")\n}","typeGuard":"func isUTF8(b []byte) bool { return utf8.Valid(b) }","tryCatchPattern":"decoded, err := decodeGB18030(body)\nif err != nil {\n\tif utf8.Valid(body) { decoded = string(body) } else { return nil, fmt.Errorf(\"[%s] 解码搜索结果失败: %w\", p.Name(), err) }\n}","preventionTips":["Detect charset from Content-Type / <meta charset> instead of hardcoding GB18030","Handle Content-Encoding: gzip before decoding","Fall back to UTF-8 when GB18030 decoding fails","Keep golang.org/x/text/encoding/simplifiedchinese up to date"],"tags":["encoding","gb18030","utf-8","scraping"],"backgroundTag":"invalid-encoding","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"}