hashicorp/nomad · error
failed to create HTTP request for Consul API URL=%q: %w
Error message
failed to create HTTP request for Consul API URL=%q: %w
What it means
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.
Source
Thrown at command/operator_debug.go:1347
return nil, fmt.Errorf("failed to configure TLS: %w", err)
}
return httpClient, nil
}
func (c *OperatorDebugCommand) collectConsulAPI(client *http.Client, urlPath string, dir string, file string) {
err := c.collectConsulAPIRequest(client, urlPath, dir, file)
if err != nil {
c.Ui.Error(fmt.Sprintf("Error collecting from Consul API: %s", err.Error()))
}
}
func (c *OperatorDebugCommand) collectConsulAPIRequest(client *http.Client, urlPath string, dir string, file string) error {
url := c.consul.addrVal + urlPath
req, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
return fmt.Errorf("failed to create HTTP request for Consul API URL=%q: %w", url, err)
}
req.Header.Add("X-Consul-Token", c.consul.token())
req.Header.Add("User-Agent", userAgent)
resp, err := client.Do(req)
if err != nil {
return err
}
c.writeBody(dir, file, resp, err)
return nil
}
// collectVault calls the Vault API directly to collect data
func (c *OperatorDebugCommand) collectVault(dir, vault string) error {
vaultAddr := c.vault.addr(vault)View on GitHub (pinned to 482b49bf1a)
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
Example fix
// before consul operator debug -http-addr=127.0.0.1:8500 // after consul operator debug -http-addr=http://127.0.0.1:8500
Defensive patterns
Strategy: validation
Validate before calling
u, err := url.Parse(addr + urlPath)
if err != nil || u.Scheme == "" || u.Host == "" {
return fmt.Errorf("invalid Consul API URL %q", addr+urlPath)
} Try / catch
req, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
return fmt.Errorf("failed to create HTTP request for Consul API URL=%q: %w", url, err)
} Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Understand the failure class
Background: "Invalid URL" / "URL cannot be empty": fix the malformed or missing URL behind request-construction failures — this error's family across 50 libraries.
Related errors
- unexpected HTTP transport: %T
- invalid address '%s': %v
- unsupported scheme: %v
- failed to configure TLS: %w
- invalid digest format
AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04).
Data as JSON: /api/errors/3fd78778021298e7.
Report an issue: GitHub.