wtfutil/wtf · error

failed to create request %s

Error message

 failed to create request
 %s

What it means

Raised in getStatus when http.NewRequest fails to construct the GET request for the Pi-hole summary API — a programming-level or URL-construction failure (e.g. invalid URL produced after query encoding), not a network problem.

Source

Thrown at modules/pihole/client.go:52

	var req *http.Request

	var url *url2.URL

	if url, err = url2.Parse(apiURL); err != nil {
		return status, fmt.Errorf(" failed to parse API URL\n %s", parseError(err))
	}

	var query url2.Values

	if query, err = url2.ParseQuery(url.RawQuery); err != nil {
		return status, fmt.Errorf(" failed to parse query\n %s", parseError(err))
	}

	query.Add("summary", "")

	url.RawQuery = query.Encode()
	if req, err = http.NewRequest("GET", url.String(), http.NoBody); err != nil {
		return status, fmt.Errorf(" failed to create request\n %s", parseError(err))
	}

	var resp *http.Response

	if resp, err = c.Do(req); err != nil || resp == nil {
		return status, fmt.Errorf(" failed to connect to Pi-hole server\n %s", parseError(err))
	}

	defer func() {
		if closeErr := resp.Body.Close(); closeErr != nil {
			return
		}
	}()

	if resp.StatusCode >= http.StatusBadRequest {
		return status, fmt.Errorf(" failed to retrieve version from Pi-hole server\n http status code: %d",
			resp.StatusCode)
	}

View on GitHub (pinned to bb838c1ccb)

Solutions

  1. Verify the final URL (parsed URL plus encoded query) is a valid absolute HTTP(S) URL
  2. Check the configured apiUrl does not contain characters that survive parsing but break request construction
  3. Update the module if this occurs with a known-good URL — it may be a client bug
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at modules/pihole/client.go:52 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of wtfutil/wtf@bb838c1ccb (2026-09-03). Data as JSON: /api/errors/46351aa84252ca49. Report an issue: GitHub.