{"record":{"id":"188a5150e577cfb6","repo":"fish2018/pansou","slug":"s-w-188a51","errorCode":null,"errorMessage":"[%s] 解析搜索页面失败: %w","messagePattern":"\\[(.+?)\\] 解析搜索页面失败: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugin/daishudj/daishudj.go","lineNumber":147,"sourceCode":"\treq, err := http.NewRequestWithContext(ctx, http.MethodGet, searchURL, nil)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"[%s] 创建搜索请求失败: %w\", p.Name(), err)\n\t}\n\tsetCommonHeaders(req, \"https://www.daishuduanju.com/\")\n\n\tresp, err := p.doRequestWithRetry(req, client)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"[%s] 搜索请求失败: %w\", p.Name(), err)\n\t}\n\tdefer resp.Body.Close()\n\n\tif resp.StatusCode != http.StatusOK {\n\t\treturn nil, fmt.Errorf(\"[%s] 搜索返回状态码: %d\", p.Name(), resp.StatusCode)\n\t}\n\n\tdoc, err := goquery.NewDocumentFromReader(resp.Body)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"[%s] 解析搜索页面失败: %w\", p.Name(), err)\n\t}\n\n\tvar (\n\t\tresults []model.SearchResult\n\t\twg      sync.WaitGroup\n\t\tmu      sync.Mutex\n\t\tsem     = make(chan struct{}, maxConcurrency)\n\t)\n\n\tdoc.Find(\".item-jx.item-blog\").Each(func(_ int, item *goquery.Selection) {\n\t\ttitleSel := item.Find(\".subtitle h5 a\")\n\t\ttitle := strings.TrimSpace(titleSel.Text())\n\t\tdetailURL, ok := titleSel.Attr(\"href\")\n\t\tif !ok || title == \"\" || detailURL == \"\" {\n\t\t\treturn\n\t\t}\n\n\t\tpostID := extractPostID(detailURL)","sourceCodeStart":129,"sourceCodeEnd":165,"githubUrl":"https://github.com/fish2018/pansou/blob/beaa56133755a548ebc51b090b3816e2ae044aa6/plugin/daishudj/daishudj.go#L129-L165","documentation":"searchImpl wraps a goquery.NewDocumentFromReader failure as \"[%s] 解析搜索页面失败\". goquery parsing only fails when reading the underlying response body fails, so this means the HTML document could not be fully read/decoded — typically a truncated or reset connection during body transfer.","triggerScenarios":"goquery.NewDocumentFromReader(resp.Body) returns an error: the connection was closed mid-body (unexpected EOF, connection reset) while streaming the search results HTML.","commonSituations":"Server/LB cutting large search-result pages, flaky proxy or VPN connections, gzip/deflate body mismatch when the client does not handle the advertised encoding, or the site throttling by dropping connections.","solutions":["Retry the search; mid-body resets are usually transient.","Read the body manually with io.ReadAll first, then parse with goquery.NewDocumentFromReader to separate I/O errors from parse issues and enable logging of partial content.","Check proxy/VPN interference and ensure the client handles Content-Encoding (gzip) consistently with the Accept-Encoding header sent in setCommonHeaders.","Increase retry/backoff so doRequestWithRetry absorbs these resets."],"exampleFix":"// before\ndoc, err := goquery.NewDocumentFromReader(resp.Body)\nif err != nil {\n    return nil, fmt.Errorf(\"[%s] 解析搜索页面失败: %w\", p.Name(), err)\n}\n// after\nbodyBytes, err := io.ReadAll(resp.Body)\nif err != nil {\n    return nil, fmt.Errorf(\"[%s] 读取搜索页面失败: %w\", p.Name(), err)\n}\ndoc, err := goquery.NewDocumentFromReader(bytes.NewReader(bodyBytes))\nif err != nil {\n    return nil, fmt.Errorf(\"[%s] 解析搜索页面失败: %w\", p.Name(), err)\n}","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"results, err := plugin.Search(ctx, keyword)\nif err != nil && strings.Contains(err.Error(), \"解析搜索页面失败\") {\n    // body transfer failed; retry once after a short delay\n    time.Sleep(time.Second)\n    results, err = plugin.Search(ctx, keyword)\n}","preventionTips":["Retry automatically once; truncated HTML responses are typically transient.","Ensure Accept-Encoding matches the encodings your client can decode.","Read the body fully before parsing so I/O and parse failures are distinguishable."],"tags":["html","go","scraping","io"],"backgroundTag":"invalid-json-response","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"}