{"record":{"id":"1856b536a8054fa5","repo":"wtfutil/wtf","slug":"invalid-request-s","errorCode":null,"errorMessage":"invalid request: %s","messagePattern":"invalid request: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"modules/pihole/client.go","lineNumber":311,"sourceCode":"\nfunc checkServer(c http.Client, apiURL string) error {\n\tvar err error\n\n\tvar req *http.Request\n\n\tvar url *url2.URL\n\n\tif url, err = url2.Parse(apiURL); err != nil {\n\t\treturn fmt.Errorf(\" failed to parse API URL\\n %s\", parseError(err))\n\t}\n\n\tif url.Host == \"\" {\n\t\treturn fmt.Errorf(\" please specify 'apiUrl' in Pi-hole settings, e.g.\\n apiUrl: http://<server>:<port>/admin/api.php\")\n\t}\n\n\tif req, err = http.NewRequest(\"GET\", fmt.Sprintf(\"%s?version\",\n\t\turl.String()), http.NoBody); err != nil {\n\t\treturn fmt.Errorf(\"invalid request: %s\", parseError(err))\n\t}\n\n\tvar resp *http.Response\n\n\tif resp, err = c.Do(req); err != nil {\n\t\treturn fmt.Errorf(\" failed to connect to Pi-hole server\\n %s\", parseError(err))\n\t}\n\n\tdefer func() {\n\t\t_ = resp.Body.Close()\n\t}()\n\n\tif resp.StatusCode >= http.StatusBadRequest {\n\t\treturn fmt.Errorf(\" failed to retrieve version from Pi-hole server\\n http status code: %d\",\n\t\t\tresp.StatusCode)\n\t}\n\n\tvar vResp struct {","sourceCodeStart":293,"sourceCodeEnd":329,"githubUrl":"https://github.com/wtfutil/wtf/blob/bb838c1ccb0f0f3223690df44afdec663d622881/modules/pihole/client.go#L293-L329","documentation":"checkServer builds a GET request to '<apiUrl>?version' to probe the server. If http.NewRequest fails to construct that request (extremely rare once the URL parses and has a Host), the library reports 'invalid request' with the underlying parseError detail.","triggerScenarios":"http.NewRequest(\"GET\", fmt.Sprintf(\"%s?version\", url.String()), http.NoBody) returns an error in checkServer — typically a context/URL issue such as an unsupported scheme after parsing.","commonSituations":"apiUrl with a scheme Go's http client cannot build a request for (e.g. ftp://), or malformed characters surviving in the parsed URL string.","solutions":["Change apiUrl to use http:// or https:// scheme","Re-test with a plain URL like http://<server>:<port>/admin/api.php","Inspect the nested parseError message for the exact request-construction problem"],"exampleFix":"// before\napiUrl: ftp://pi.hole/admin/api.php\n// after\napiUrl: http://pi.hole/admin/api.php","handlingStrategy":"validation","validationCode":"u, err := url.Parse(apiURL)\nif err != nil {\n    return err\n}\nif u.Scheme != \"http\" && u.Scheme != \"https\" {\n    return fmt.Errorf(\"unsupported scheme %q for apiUrl\", u.Scheme)\n}","typeGuard":null,"tryCatchPattern":"if err := widget.checkServer(*client, apiUrl); err != nil {\n    if strings.HasPrefix(err.Error(), \"invalid request\") {\n        log.Printf(\"fix apiUrl scheme/format: %v\", err)\n    }\n}","preventionTips":["Use only http:// or https:// schemes for apiUrl","Avoid embedding credentials or odd characters in the URL","Validate the composed URL (<apiUrl>?version) manually with curl"],"tags":["http-request","pi-hole","configuration","url"],"backgroundTag":"invalid-request-construction","analyzedSha":"bb838c1ccb0f0f3223690df44afdec663d622881","analyzedAt":"2026-09-03T17:02:45.030Z","contentChangedAt":"2026-09-03T17:02:45.030Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}