{"record":{"id":"d861fb664d7ddbdc","repo":"fish2018/pansou","slug":"s-w-d861fb","errorCode":null,"errorMessage":"[%s] 创建请求失败: %w","messagePattern":"\\[(.+?)\\] 创建请求失败: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugin/xdyh/xdyh.go","lineNumber":136,"sourceCode":"\t\tMaxWorkers: 10,   // API默认并发数\n\t\tSaveToFile: false,\n\t\tSplitLinks: true,\n\t}\n\t\n\t// 3. JSON序列化\n\tjsonData, err := json.Marshal(requestBody)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"[%s] JSON序列化失败: %w\", pluginName, err)\n\t}\n\t\n\t// 4. 创建带超时的上下文\n\tctx, cancel := context.WithTimeout(context.Background(), DefaultTimeout)\n\tdefer cancel()\n\t\n\t// 5. 创建请求\n\treq, err := http.NewRequestWithContext(ctx, \"POST\", apiURL, bytes.NewBuffer(jsonData))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"[%s] 创建请求失败: %w\", pluginName, err)\n\t}\n\t\n\t// 6. 设置请求头\n\tp.setRequestHeaders(req)\n\t\n\t// 7. 发送请求\n\tresp, err := p.doRequestWithRetry(req, client)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"[%s] 搜索请求失败: %w\", pluginName, err)\n\t}\n\tdefer resp.Body.Close()\n\t\n\t// 8. 检查状态码\n\tif resp.StatusCode != 200 {\n\t\treturn nil, fmt.Errorf(\"[%s] 请求返回状态码: %d\", pluginName, resp.StatusCode)\n\t}\n\t\n\t// 9. 读取响应体","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/fish2018/pansou/blob/beaa56133755a548ebc51b090b3816e2ae044aa6/plugin/xdyh/xdyh.go#L118-L154","documentation":"http.NewRequestWithContext failed while building the POST request to the API URL. This occurs before any network I/O and almost always means the URL failed to parse or the body/io.Reader itself errored.","triggerScenarios":"apiURL is malformed (bad scheme, spaces, control characters) or the request body reader returns an error when NewRequest reads it into memory.","commonSituations":"apiURL built from an empty or misconfigured base URL; configuration containing whitespace or invalid characters interpolated into the URL; constant leaked into apiURL.","solutions":["Print/validate apiURL before constructing the request (url.Parse the constant at init)","Check the wrapped error's message for 'parse ...: invalid ...' hints","Fix the configuration or constant supplying apiURL"],"exampleFix":"// before\nreq, err := http.NewRequestWithContext(ctx, \"POST\", apiURL, bytes.NewBuffer(jsonData))\n// after\nif _, perr := url.Parse(apiURL); perr != nil {\n    return nil, fmt.Errorf(\"无效的API地址 %q: %w\", apiURL, perr)\n}\nreq, err := http.NewRequestWithContext(ctx, \"POST\", apiURL, bytes.NewBuffer(jsonData))","handlingStrategy":"validation","validationCode":"u, err := url.Parse(apiURL)\nif err != nil || u.Scheme == \"\" || u.Host == \"\" {\n    return fmt.Errorf(\"无效的API地址: %q\", apiURL)\n}","typeGuard":null,"tryCatchPattern":"req, err := http.NewRequestWithContext(ctx, \"POST\", apiURL, bytes.NewBuffer(jsonData))\nif err != nil {\n    return nil, fmt.Errorf(\"[%s] 创建请求失败: %w\", pluginName, err)\n}","preventionTips":["Validate apiURL at plugin init with url.Parse","Never interpolate raw user/config strings into URLs without escaping","Pin the API URL as a validated constant"],"tags":["http","url","configuration"],"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"}