{"record":{"id":"3fd78778021298e7","repo":"hashicorp/nomad","slug":"failed-to-create-http-request-for-consul-api-url","errorCode":null,"errorMessage":"failed to create HTTP request for Consul API URL=%q: %w","messagePattern":"failed to create HTTP request for Consul API URL=%q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/operator_debug.go","lineNumber":1347,"sourceCode":"\t\treturn nil, fmt.Errorf(\"failed to configure TLS: %w\", err)\n\t}\n\n\treturn httpClient, nil\n}\n\nfunc (c *OperatorDebugCommand) collectConsulAPI(client *http.Client, urlPath string, dir string, file string) {\n\terr := c.collectConsulAPIRequest(client, urlPath, dir, file)\n\tif err != nil {\n\t\tc.Ui.Error(fmt.Sprintf(\"Error collecting from Consul API: %s\", err.Error()))\n\t}\n}\n\nfunc (c *OperatorDebugCommand) collectConsulAPIRequest(client *http.Client, urlPath string, dir string, file string) error {\n\turl := c.consul.addrVal + urlPath\n\n\treq, err := http.NewRequest(http.MethodGet, url, nil)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to create HTTP request for Consul API URL=%q: %w\", url, err)\n\t}\n\n\treq.Header.Add(\"X-Consul-Token\", c.consul.token())\n\treq.Header.Add(\"User-Agent\", userAgent)\n\n\tresp, err := client.Do(req)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tc.writeBody(dir, file, resp, err)\n\n\treturn nil\n}\n\n// collectVault calls the Vault API directly to collect data\nfunc (c *OperatorDebugCommand) collectVault(dir, vault string) error {\n\tvaultAddr := c.vault.addr(vault)","sourceCodeStart":1329,"sourceCodeEnd":1365,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/operator_debug.go#L1329-L1365","documentation":"collectConsulAPIRequest constructs the GET request for each Consul API endpoint by concatenating the Consul address with the URL path (c.consul.addrVal + urlPath) and calling http.NewRequest. If NewRequest fails, the URL itself is malformed, and the full URL is included in the wrapped error. Failure here means no request is ever sent for that endpoint.","triggerScenarios":"http.NewRequest(http.MethodGet, url, nil) errors — the composed URL fails url.Parse: invalid scheme/host in -http-addr (e.g. missing scheme like '127.0.0.1:8500' without http://, or control characters/invalid percent-escapes in the path).","commonSituations":"Setting -http-addr to '127.0.0.1:8500' or 'consul:8500' without an http:// scheme; leftover whitespace or quotes in the address from shell interpolation; garbage characters introduced by scripting the address.","solutions":["Read the wrapped cause and the echoed URL to see exactly what was parsed","Fix -http-addr to include the scheme: http://127.0.0.1:8500 (or https:// for TLS)","Trim whitespace/quotes from the address value in scripts and env vars","Validate the address first with curl <addr>/v1/status/leader before re-running the capture"],"exampleFix":"// before\nconsul operator debug -http-addr=127.0.0.1:8500\n// after\nconsul operator debug -http-addr=http://127.0.0.1:8500","handlingStrategy":"validation","validationCode":"u, err := url.Parse(addr + urlPath)\nif err != nil || u.Scheme == \"\" || u.Host == \"\" {\n\treturn fmt.Errorf(\"invalid Consul API URL %q\", addr+urlPath)\n}","typeGuard":null,"tryCatchPattern":"req, err := http.NewRequest(http.MethodGet, url, nil)\nif err != nil {\n\treturn fmt.Errorf(\"failed to create HTTP request for Consul API URL=%q: %w\", url, err)\n}","preventionTips":["Always include the scheme in -http-addr (http:// or https://)","Trim whitespace and shell quotes from address values in scripts","Sanity-check the address with curl before running the capture"],"tags":["http","url","consul-api","configuration"],"backgroundTag":"invalid-url","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}