{"record":{"id":"a55ee4f09440465b","repo":"fish2018/pansou","slug":"w-a55ee4","errorCode":null,"errorMessage":"创建请求失败: %w","messagePattern":"创建请求失败: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugin/pansearch/pansearch.go","lineNumber":372,"sourceCode":"\n\t// 双重检查\n\tif buildIdCache != \"\" && time.Since(buildIdCacheTime) < BuildIdCacheDuration*time.Minute {\n\t\treturn buildIdCache, nil\n\t}\n\n\t// 创建带超时的上下文\n\tctx, cancel := context.WithTimeout(context.Background(), p.timeout)\n\tdefer cancel()\n\n\t// 发送请求获取页面\n\treq, err := http.NewRequestWithContext(ctx, \"GET\", WebsiteURL, nil)\n\tif err != nil {\n\t\t// 如果创建请求失败但有旧的缓存，使用旧的缓存（优雅降级）\n\t\tif buildIdCache != \"\" {\n\t\t\t// fmt.Printf(\"创建请求失败，使用旧的buildId: %v\\n\", err)\n\t\t\treturn buildIdCache, nil\n\t\t}\n\t\treturn \"\", fmt.Errorf(\"创建请求失败: %w\", 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\", \"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8\")\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(\"Upgrade-Insecure-Requests\", \"1\")\n\treq.Header.Set(\"Cache-Control\", \"max-age=0\")\n\n\tclient = p.requestClient(client)\n\n\t// 使用重试机制发送请求\n\tvar resp *http.Response\n\tvar respErr error\n\n\tfor retry := 0; retry <= p.retries; retry++ {\n\t\tif retry > 0 {","sourceCodeStart":354,"sourceCodeEnd":390,"githubUrl":"https://github.com/fish2018/pansou/blob/beaa56133755a548ebc51b090b3816e2ae044aa6/plugin/pansearch/pansearch.go#L354-L390","documentation":"In getBuildId (pansearch plugin), http.NewRequest fails while trying to fetch the site's buildId. The function normally falls back to a cached buildId for graceful degradation, but if no cache exists it returns this wrapped error.","triggerScenarios":"http.NewRequestWithContext returns an error for the site URL — malformed URL, unsupported scheme, or context already canceled before request creation — and buildIdCache is empty.","commonSituations":"Site base URL misconfigured (invalid characters/spaces in URL); caller-supplied context canceled or deadline exceeded before the request starts; first run with no cached buildId and a bad configured URL.","solutions":["Validate the pansearch base URL is a well-formed absolute http(s) URL","Ensure the context passed in is not already canceled/deadlined-exceeded","Pre-warm buildIdCache by calling getBuildId once at startup so fallback exists later","Retry after fixing configuration; the error is deterministic until the URL or context is fixed"],"exampleFix":"// before\nbuildId, err := getBuildId(ctx)\nif err != nil { return \"\", err }\n// after\nu, err := url.Parse(siteBaseURL)\nif err != nil || u.Scheme == \"\" {\n    return \"\", fmt.Errorf(\"invalid pansearch base URL: %q\", siteBaseURL)\n}\nbuildId, err := getBuildId(ctx)\nif err != nil { return \"\", err }","handlingStrategy":"validation","validationCode":"u, err := url.Parse(siteBaseURL)\nif err != nil || (u.Scheme != \"http\" && u.Scheme != \"https\") || u.Host == \"\" {\n    return fmt.Errorf(\"invalid site URL: %q\", siteBaseURL)\n}\nif ctx.Err() != nil {\n    return ctx.Err()\n}","typeGuard":null,"tryCatchPattern":"buildId, err := getBuildId(ctx)\nif err != nil {\n    if strings.Contains(err.Error(), \"创建请求失败\") {\n        return fmt.Errorf(\"buildId fetch could not start (bad URL/context): %w\", err)\n    }\n    return err\n}","preventionTips":["Validate the base URL at startup","Pre-warm the buildId cache so fallback is available on later failures","Pass live, non-canceled contexts to getBuildId"],"tags":["http","url","network","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"}