{"record":{"id":"652eb5b0955278da","repo":"fish2018/pansou","slug":"create-request-failed-w","errorCode":null,"errorMessage":"create request failed: %w","messagePattern":"create request failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugin/jikepan/jikepan.go","lineNumber":75,"sourceCode":"\t\t\"is_all\": false,\n\t}\n\t\n\t// 检查ext中是否包含自定义参数，如果有则使用它\n\tif ext != nil {\n\t\tif isAll, ok := ext[\"is_all\"].(bool); ok && isAll {\n\t\t\t// 使用全量搜索，时间大约10秒\n\t\t\treqBody[\"is_all\"] = true\n\t\t}\n\t}\n\t\n\tjsonData, err := json.Marshal(reqBody)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"marshal request failed: %w\", err)\n\t}\n\t\n\treq, err := http.NewRequest(\"POST\", JikepanAPIURL, bytes.NewBuffer(jsonData))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"create request failed: %w\", err)\n\t}\n\t\n\treq.Header.Set(\"Content-Type\", \"application/json\")\n\treq.Header.Set(\"referer\", \"https://jikepan.xyz/\")\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\t\n\t// 发送请求\n\tresp, err := client.Do(req)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"request failed: %w\", err)\n\t}\n\tdefer resp.Body.Close()\n\t\n\t// 解析响应\n\tvar apiResp JikepanResponse\n\tbodyBytes, err := io.ReadAll(resp.Body)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"read response body failed: %w\", err)","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/fish2018/pansou/blob/beaa56133755a548ebc51b090b3816e2ae044aa6/plugin/jikepan/jikepan.go#L57-L93","documentation":"After marshaling the body, doSearch creates the POST request to JikepanAPIURL via http.NewRequest. If the request cannot be constructed (malformed URL, invalid method/context), the error is wrapped as \"create request failed\".","triggerScenarios":"http.NewRequest(\"POST\", JikepanAPIURL, ...) fails — typically because JikepanAPIURL is an empty string or not a parseable absolute URL (bad build-time constant or misconfigured endpoint).","commonSituations":"Endpoint constant mis-typed or stripped during refactoring; environment-specific config overriding the URL with an invalid value; missing scheme (e.g. \"jikepan.xyz/search\" without https://).","solutions":["Print/verify JikepanAPIURL is a valid absolute http(s) URL","Use url.Parse on the constant to validate at startup","Restore the correct default JikepanAPIURL constant","Prefer http.NewRequestWithContext with a caller context for cancellation"],"exampleFix":"// before\nreq, err := http.NewRequest(\"POST\", JikepanAPIURL, bytes.NewBuffer(jsonData))\nif err != nil {\n\treturn nil, fmt.Errorf(\"create request failed: %w\", err)\n}\n\n// after\nif u, perr := url.Parse(JikepanAPIURL); perr != nil || u.Scheme == \"\" || u.Host == \"\" {\n\treturn nil, fmt.Errorf(\"invalid JikepanAPIURL: %q\", JikepanAPIURL)\n}\nreq, err := http.NewRequestWithContext(ctx, http.MethodPost, JikepanAPIURL, bytes.NewBuffer(jsonData))\nif err != nil {\n\treturn nil, fmt.Errorf(\"create request failed: %w\", err)\n}","handlingStrategy":"validation","validationCode":"u, err := url.Parse(JikepanAPIURL)\nif err != nil || u.Scheme == \"\" || u.Host == \"\" {\n\treturn fmt.Errorf(\"invalid JikepanAPIURL: %q\", JikepanAPIURL)\n}","typeGuard":null,"tryCatchPattern":"// Go\nresults, err := p.doSearch(ctx, keyword, ext)\nif err != nil && strings.Contains(err.Error(), \"create request failed\") {\n\tlog.Printf(\"jikepan endpoint misconfigured: %v\", err)\n}","preventionTips":["Validate endpoint constants at plugin init","Keep the URL in one well-tested constant","Use http.NewRequestWithContext for cancellation support"],"tags":["http","request","url"],"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"}