{"record":{"id":"c10dca3ac7a4bd60","repo":"fish2018/pansou","slug":"create-request-failed-w-c10dca","errorCode":null,"errorMessage":"create request failed: %w","messagePattern":"create request failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugin/melost/melost.go","lineNumber":160,"sourceCode":"\t\t\t\"wechat_pwd\":  \"\",\n\t\t\t\"search_code\": \"\",\n\t\t\t\"platform\":    \"pc\",\n\t\t\t\"fp_data\":     \"\",\n\t\t\t\"automated\":   DefaultAutomated,\n\t\t},\n\t}\n\n\tjsonData, err := json.Marshal(reqBody)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"marshal request failed: %w\", err)\n\t}\n\n\tctx, cancel := context.WithTimeout(context.Background(), DefaultTimeout)\n\tdefer cancel()\n\n\treq, err := http.NewRequestWithContext(ctx, \"POST\", MelostSearchAPI, bytes.NewBuffer(jsonData))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"create request failed: %w\", err)\n\t}\n\n\treq.Header.Set(\"Content-Type\", \"application/json\")\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(\"Origin\", \"https://www.melost.cn\")\n\treq.Header.Set(\"Referer\", DefaultReferer)\n\treq.Header.Set(\"User-Agent\", \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36\")\n\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\n\tif resp.StatusCode != http.StatusOK {\n\t\treturn nil, fmt.Errorf(\"unexpected status code: %d\", resp.StatusCode)\n\t}","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/fish2018/pansou/blob/beaa56133755a548ebc51b090b3816e2ae044aa6/plugin/melost/melost.go#L142-L178","documentation":"searchPage builds the POST request with http.NewRequestWithContext targeting MelostSearchAPI; if NewRequestWithContext fails (e.g. invalid URL), the error is wrapped as \"create request failed: %w\". This indicates the configured MelostSearchAPI URL is malformed or the context/method arguments are invalid.","triggerScenarios":"MelostSearchAPI constant contains an unparsable URL (missing scheme, illegal characters, control characters), or a non-nil invalid context is passed to NewRequestWithContext.","commonSituations":"A bad constant edit after a site migration (URL typo, missing https://), or MelostSearchAPI read from user config with an invalid value.","solutions":["Read the wrapped error; net/url parse errors identify the malformed part of the URL","Print/inspect the MelostSearchAPI constant and fix the URL (add scheme, escape special characters)","If the URL comes from configuration, validate it with url.Parse before constructing the request","Verify no control characters or whitespace leaked into the endpoint string"],"exampleFix":"// before: constant typo breaks NewRequest\nconst MelostSearchAPI = \"htp://www.melost.cn/api/search\"\n// after\nconst MelostSearchAPI = \"https://www.melost.cn/api/search\"","handlingStrategy":"validation","validationCode":"u, err := url.Parse(MelostSearchAPI)\nif err != nil || u.Scheme == \"\" || u.Host == \"\" {\n\treturn nil, fmt.Errorf(\"invalid MelostSearchAPI URL: %q\", MelostSearchAPI)\n}","typeGuard":null,"tryCatchPattern":"req, err := http.NewRequestWithContext(ctx, \"POST\", MelostSearchAPI, bytes.NewBuffer(jsonData))\nif err != nil {\n\treturn nil, fmt.Errorf(\"create request failed: %w\", err)\n}","preventionTips":["Validate endpoint URLs with url.Parse at startup, not per-request","Always include the scheme (https://) in endpoint constants","If the URL is configurable, sanitize/trim user input before use","Add a startup smoke test that builds a request against the 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"}