{"record":{"id":"1dcfbc79424c2f90","repo":"thanos-io/thanos","slug":"create-request","errorCode":null,"errorMessage":"create request","messagePattern":"create request","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/promclient/promclient.go","lineNumber":298,"sourceCode":"\t}\n\n\tboolean, err := strconv.ParseBool(s)\n\tif err != nil {\n\t\treturn err\n\t}\n\t*m = modelBool(boolean)\n\treturn nil\n}\n\n// ConfiguredFlags returns configured flags from /api/v1/status/flags Prometheus endpoint.\n// Added to Prometheus from v2.2.\nfunc (c *Client) ConfiguredFlags(ctx context.Context, base *url.URL) (Flags, error) {\n\tu := *base\n\tu.Path = path.Join(u.Path, \"/api/v1/status/flags\")\n\n\treq, err := http.NewRequest(http.MethodGet, u.String(), nil)\n\tif err != nil {\n\t\treturn Flags{}, errors.Wrap(err, \"create request\")\n\t}\n\n\tspan, ctx := tracing.StartSpan(ctx, \"/prom_flags HTTP[client]\")\n\tdefer span.Finish()\n\n\tresp, err := c.Do(req.WithContext(ctx))\n\tif err != nil {\n\t\treturn Flags{}, errors.Wrapf(err, \"request config against %s\", u.String())\n\t}\n\tdefer runutil.ExhaustCloseWithLogOnErr(c.logger, resp.Body, \"query body\")\n\n\tb, err := io.ReadAll(resp.Body)\n\tif err != nil {\n\t\treturn Flags{}, errors.New(\"failed to read body\")\n\t}\n\n\tswitch resp.StatusCode {\n\tcase 404:","sourceCodeStart":280,"sourceCodeEnd":316,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/promclient/promclient.go#L280-L316","documentation":"ConfiguredFlags builds a GET request to <base>/api/v1/status/flags via http.NewRequest; this error wraps any failure of request construction, such as a malformed URL produced from the base URL. It means the HTTP request could not even be created, before any network I/O.","triggerScenarios":"http.NewRequest fails — practically only when the composed URL (base URL joined with /api/v1/status/flags) is invalid, e.g. base URL containing control characters or an unparseable scheme/host. Called by an anonymous caller reading Prometheus flags.","commonSituations":"A base URL read from config/environment contains whitespace, newlines, or invalid characters; empty or malformed --prometheus.url flag value; templating produced a bad URL.","solutions":["Validate the base URL string with url.Parse before passing it to the client","Fix the --prometheus.url / configured base URL (scheme://host:port, no stray characters)","Trim whitespace/newlines from URL values coming from config files or env vars","Log u.String() to see the exact URL being built"],"exampleFix":"// before\nbase := os.Getenv(\"PROM_URL\") // \"http://prom:9090\\n\"\nclient.ConfiguredFlags(ctx, mustParse(base))\n// after\nu, err := url.Parse(strings.TrimSpace(os.Getenv(\"PROM_URL\")))\nif err != nil { return err }\nif u.Scheme == \"\" || u.Host == \"\" { return errors.New(\"invalid prometheus url\") }\nclient.ConfiguredFlags(ctx, u)","handlingStrategy":"validation","validationCode":"func validBaseURL(raw string) (*url.URL, error) {\n    u, err := url.Parse(strings.TrimSpace(raw))\n    if err != nil { return nil, err }\n    if u.Scheme == \"\" || u.Host == \"\" {\n        return nil, fmt.Errorf(\"base URL must include scheme and host: %q\", raw)\n    }\n    return u, nil\n}","typeGuard":null,"tryCatchPattern":"flags, err := client.ConfiguredFlags(ctx, u)\nif err != nil {\n    if strings.Contains(err.Error(), \"create request\") {\n        return fmt.Errorf(\"invalid prometheus URL %q: %w\", u, err)\n    }\n    return err\n}","preventionTips":["Parse and validate URLs with url.Parse at config load time","Trim whitespace from URLs read from env/config files","Reject URLs without scheme/host during configuration validation"],"tags":["http","url","request-construction"],"backgroundTag":"invalid-url","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"}