{"record":{"id":"672bb229a13c2d82","repo":"fish2018/pansou","slug":"w-672bb2","errorCode":null,"errorMessage":"创建详情页请求失败: %w","messagePattern":"创建详情页请求失败: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugin/wuji/wuji.go","lineNumber":308,"sourceCode":"\t// 检查缓存\n\tif cached, ok := magnetCache.Load(detailURL); ok {\n\t\tif entry, ok := cached.(magnetCacheEntry); ok {\n\t\t\tif time.Since(entry.Timestamp) < cacheTTL {\n\t\t\t\t// 缓存命中\n\t\t\t\treturn entry.MagnetLink, nil\n\t\t\t}\n\t\t\t// 缓存过期，删除\n\t\t\tmagnetCache.Delete(detailURL)\n\t\t}\n\t}\n\t// 创建带超时的上下文\n\tctx, cancel := context.WithTimeout(context.Background(), TimeoutSeconds*time.Second)\n\tdefer cancel()\n\t\n\t// 创建请求\n\treq, err := http.NewRequestWithContext(ctx, \"GET\", detailURL, nil)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"创建详情页请求失败: %w\", err)\n\t}\n\t\n\t// 设置请求头\n\tp.setRequestHeaders(req)\n\t\n\t// 发送HTTP请求\n\tresp, err := p.doRequestWithRetry(req, client)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"详情页请求失败: %w\", err)\n\t}\n\tdefer resp.Body.Close()\n\t\n\t// 检查状态码\n\tif resp.StatusCode != 200 {\n\t\treturn \"\", fmt.Errorf(\"详情页返回状态码: %d\", resp.StatusCode)\n\t}\n\t\n\t// 读取响应体内容","sourceCodeStart":290,"sourceCodeEnd":326,"githubUrl":"https://github.com/fish2018/pansou/blob/beaa56133755a548ebc51b090b3816e2ae044aa6/plugin/wuji/wuji.go#L290-L326","documentation":"In WujiPlugin.fetchMagnetLink the plugin builds a GET request for the detail page with http.NewRequestWithContext under a TimeoutSeconds timeout. This error wraps any failure of http.NewRequestWithContext itself — it fires before any network I/O happens. Typical causes are a malformed/unparseable detailURL, an unsupported URL scheme, or a nil/invalid context.","triggerScenarios":"fetchMagnetLink is called with a detailURL that http.NewRequestWithContext cannot parse: empty string, missing scheme, invalid characters, control characters in the URL, or a non-http(s) scheme. Also fires if the timeout context is already invalid.","commonSituations":"Scraped hrefs from search results that are empty or relative and never resolved against the site base URL; detail URLs containing spaces or unencoded Chinese characters taken straight from HTML attributes; site layout change producing href=\"\" for every result.","solutions":["Log the detailURL value when this error occurs and inspect it for emptiness, spaces, or missing scheme.","Resolve scraped hrefs against the site base before calling fetchMagnetLink, e.g. resp.Request.URL.Parse(href) or url.Parse + ResolveReference.","Validate the URL with url.ParseRequestURI(detailURL) and skip results with invalid links instead of letting the error propagate.","Skip enrichment for a result whose Links slice is empty (enrichWithMagnetLinks already checks len(Links)==0; make sure the link value itself is non-empty too)."],"exampleFix":"// before\nmagnet, err := p.fetchMagnetLink(client, link.Href)\n// after\nu, perr := url.Parse(strings.TrimSpace(link.Href))\nif perr != nil || u.Scheme == \"\" {\n    continue // skip invalid detail URL\n}\nmagnet, err := p.fetchMagnetLink(client, base.ResolveReference(u).String())","handlingStrategy":"validation","validationCode":"u, err := url.ParseRequestURI(strings.TrimSpace(detailURL))\nif err != nil || (u.Scheme != \"http\" && u.Scheme != \"https\") {\n    // skip this result; don't call fetchMagnetLink\n}","typeGuard":null,"tryCatchPattern":"magnet, err := p.fetchMagnetLink(client, detailURL)\nif err != nil {\n    log.Printf(\"magnet fetch failed for %s: %v\", detailURL, err)\n    return \"\"\n}","preventionTips":["Always resolve scraped hrefs against the site base URL before use","Trim whitespace and URL-encode paths extracted from HTML attributes","Skip results with empty or scheme-less links instead of attempting enrichment"],"tags":["network","http","url-parsing","scraping"],"backgroundTag":"invalid-url-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"}