{"record":{"id":"de804b0e4fdc589e","repo":"thanos-io/thanos","slug":"create-s-request","errorCode":null,"errorMessage":"create %s request","messagePattern":"create (.+?) request","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/promclient/promclient.go","lineNumber":120,"sourceCode":"\t\thttpClient,\n\t\tlogger,\n\t\tuserAgent,\n\t)\n}\n\n// req2xx sends a request to the given url.URL. If method is http.MethodPost then\n// the raw query is encoded in the body and the appropriate Content-Type is set.\nfunc (c *Client) req2xx(ctx context.Context, u *url.URL, method string, headers http.Header) (_ []byte, _ int, err error) {\n\tvar b io.Reader\n\tif method == http.MethodPost {\n\t\trq := u.RawQuery\n\t\tb = strings.NewReader(rq)\n\t\tu.RawQuery = \"\"\n\t}\n\n\treq, err := http.NewRequest(method, u.String(), b)\n\tif err != nil {\n\t\treturn nil, 0, errors.Wrapf(err, \"create %s request\", method)\n\t}\n\tif headers != nil {\n\t\treq.Header = headers\n\t}\n\n\tif c.userAgent != \"\" {\n\t\treq.Header.Set(\"User-Agent\", c.userAgent)\n\t}\n\tif method == http.MethodPost {\n\t\treq.Header.Set(\"Content-Type\", \"application/x-www-form-urlencoded\")\n\t}\n\n\tresp, err := c.Do(req.WithContext(ctx))\n\tif err != nil {\n\t\treturn nil, 0, errors.Wrapf(err, \"perform %s request against %s\", method, u.String())\n\t}\n\tdefer runutil.ExhaustCloseWithErrCapture(&err, resp.Body, \"%s: close body\", req.URL.String())\n","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/promclient/promclient.go#L102-L138","documentation":"In promclient's req2xx helper, http.NewRequest failed while building the outgoing API request. The error wraps the underlying reason (bad method, unparseable URL, invalid body) with the message \"create <method> request\". No network traffic has happened yet.","triggerScenarios":"Calling any client wrapper (ExternalLabels, QueryInstant, QueryRange, AlertmanagerAlerts, BuildVersion) with a URL that fails url.Parse or an invalid HTTP method, e.g. a malformed promURL containing spaces or bad characters.","commonSituations":"Misconfigured --prometheus.url flag with typos or unencoded characters; programmatically built URLs missing scheme (\"localhost:9090\" without http://); empty base URL.","solutions":["Validate the base URL with url.Parse and require a scheme before calling the client","URL-encode query values (url.Values.Encode) instead of string concatenation","Use only valid HTTP method constants","Log/inspect the wrapped error to see which URL component failed"],"exampleFix":"// before\nu, _ := url.Parse(baseURL + \"/api/v1/query?query=\" + query)\n// after\nu, err := url.Parse(baseURL)\nif err != nil { return err }\nu.Path = \"/api/v1/query\"\nu.RawQuery = url.Values{\"query\": []string{query}}.Encode()","handlingStrategy":"validation","validationCode":"u, err := url.Parse(promURL)\nif err != nil || u.Scheme == \"\" || u.Host == \"\" {\n    return fmt.Errorf(\"invalid prometheus URL %q\", promURL)\n}","typeGuard":"func isValidURL(raw string) bool {\n    u, err := url.Parse(raw)\n    return err == nil && (u.Scheme == \"http\" || u.Scheme == \"https\") && u.Host != \"\"\n}","tryCatchPattern":"flags, _, err := client.BuildVersion(ctx, promURL)\nif err != nil && strings.Contains(err.Error(), \"create request\") {\n    // malformed URL/method: fix config, do not retry\n    return err\n}","preventionTips":["Build URLs with url.Values and url.Parse, never string concatenation","Require scheme+host in URL config flags and validate at startup","Only use standard HTTP method constants"],"tags":["http","url","client"],"backgroundTag":"invalid-url-format","analyzedSha":"35b8b991177def87ed52dcf10f9b6d87f07282c8","analyzedAt":"2026-09-07T01:49:59.689Z","contentChangedAt":"2026-09-07T01:49:59.689Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}