{"record":{"id":"f79dbe9c35ce4961","repo":"fish2018/pansou","slug":"s-hsid-s-w","errorCode":null,"errorMessage":"[%s] hsid=%s创建链接请求失败: %w","messagePattern":"\\[(.+?)\\] hsid=(.+?)创建链接请求失败: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugin/haisou/haisou.go","lineNumber":390,"sourceCode":"}\n\n// fetchShareLink 通过hsid获取具体的分享链接\nfunc (p *HaisouPlugin) fetchShareLink(client *http.Client, hsid string, platform string) (string, string, error) {\n\t// 构建获取链接的URL\n\tfetchURL := fmt.Sprintf(\"https://haisou.cc/api/pan/share/%s/fetch\", hsid)\n\n\tif DebugLog {\n\t\tfmt.Printf(\"[%s] 获取链接 hsid=%s platform=%s: %s\\n\", p.Name(), hsid, platform, fetchURL)\n\t}\n\n\t// 创建带超时的上下文\n\tctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)\n\tdefer cancel()\n\n\t// 创建请求对象\n\treq, err := http.NewRequestWithContext(ctx, \"GET\", fetchURL, nil)\n\tif err != nil {\n\t\treturn \"\", \"\", fmt.Errorf(\"[%s] hsid=%s创建链接请求失败: %w\", p.Name(), hsid, err)\n\t}\n\n\t// 设置请求头\n\treq.Header.Set(\"User-Agent\", \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36\")\n\treq.Header.Set(\"Accept\", \"application/json, text/plain, */*\")\n\treq.Header.Set(\"Accept-Language\", \"zh-CN,zh;q=0.9,en;q=0.8\")\n\treq.Header.Set(\"Connection\", \"keep-alive\")\n\treq.Header.Set(\"Referer\", \"https://haisou.cc/\")\n\n\t// 发送HTTP请求（带重试机制）\n\tresp, err := p.doRequestWithRetry(req, client)\n\tif err != nil {\n\t\treturn \"\", \"\", fmt.Errorf(\"[%s] hsid=%s链接请求失败: %w\", p.Name(), hsid, err)\n\t}\n\tdefer resp.Body.Close()\n\n\t// 检查状态码\n\tif resp.StatusCode != 200 {","sourceCodeStart":372,"sourceCodeEnd":408,"githubUrl":"https://github.com/fish2018/pansou/blob/beaa56133755a548ebc51b090b3816e2ae044aa6/plugin/haisou/haisou.go#L372-L408","documentation":"This error is thrown by fetchShareLink when http.NewRequestWithContext fails to construct the GET request for converting a hsid into a share link. This is rare — it usually means the fetchURL was malformed (invalid method/URL) or the 15s-timeout context was already expired/invalid before the request was created.","triggerScenarios":"http.NewRequestWithContext(ctx, \"GET\", fetchURL, nil) returns an error inside fetchShareLink — typically because fetchURL fails url.Parse or the context is invalid.","commonSituations":"The hsid or platform value interpolated into fetchURL contains characters that break the URL; fetchURL built with an empty hsid; caller-provided context already cancelled; URL containing spaces or unencoded Chinese characters.","solutions":["Log fetchURL when this fires and validate it with url.Parse before constructing the request","url.PathEscape / url.QueryEscape the hsid before interpolating it into fetchURL","Check that hsid is non-empty before calling fetchShareLink","Use context.WithTimeout on a caller-supplied context rather than Background so cancellation is traceable"],"exampleFix":"// before\nreq, err := http.NewRequestWithContext(ctx, \"GET\", fetchURL, nil)\nif err != nil {\n\treturn \"\", \"\", fmt.Errorf(\"[%s] hsid=%s创建链接请求失败: %w\", p.Name(), hsid, err)\n}\n// after\nif hsid == \"\" {\n\treturn \"\", \"\", fmt.Errorf(\"[%s] hsid为空，无法创建链接请求\", p.Name())\n}\nif _, perr := url.Parse(fetchURL); perr != nil {\n\treturn \"\", \"\", fmt.Errorf(\"[%s] fetchURL非法 (%s): %w\", p.Name(), fetchURL, perr)\n}\nreq, err := http.NewRequestWithContext(ctx, \"GET\", fetchURL, nil)\nif err != nil {\n\treturn \"\", \"\", fmt.Errorf(\"[%s] hsid=%s创建链接请求失败: %w\", p.Name(), hsid, err)\n}","handlingStrategy":"validation","validationCode":"if hsid == \"\" {\n\treturn errors.New(\"hsid is empty\")\n}\nif _, err := url.Parse(fetchURL); err != nil {\n\treturn fmt.Errorf(\"invalid fetchURL %q: %w\", fetchURL, err)\n}","typeGuard":null,"tryCatchPattern":"req, err := http.NewRequestWithContext(ctx, \"GET\", fetchURL, nil)\nif err != nil {\n\treturn fmt.Errorf(\"build request failed for hsid=%s: %w\", hsid, err)\n}","preventionTips":["Always escape hsid/keyword values interpolated into URLs","Reject empty identifiers before making requests","Pass caller contexts down instead of building Background contexts","Unit-test URL construction with unusual hsid values"],"tags":["http","request","url","go"],"backgroundTag":"invalid-url","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"}