glanceapp/glance · error

creating request: %w

Error message

creating request: %w

What it means

http.NewRequestWithContext failed while constructing GET http://<hostname>/containers/json?all=<true|false>. Because the URL is assembled from a validated host:port plus a fixed path, this is nearly unreachable — it signals the hostname derived earlier contains characters that break URL parsing.

Source

Thrown at internal/glance/widget-docker-containers.go:322

	} else {
		hostname = "docker"
		client = &http.Client{
			Transport: &http.Transport{
				DialContext: func(_ context.Context, _, _ string) (net.Conn, error) {
					return net.Dial("unix", source)
				},
			},
		}
	}


	fetchAll := ternary(runningOnly, "false", "true")
	ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
	defer cancel()

	request, err := http.NewRequestWithContext(ctx, "GET", "http://"+hostname+"/containers/json?all="+fetchAll, nil)
	if err != nil {
		return nil, fmt.Errorf("creating request: %w", err)
	}

	response, err := client.Do(request)
	if err != nil {
		return nil, fmt.Errorf("sending request to socket: %w", err)
	}
	defer response.Body.Close()

	if response.StatusCode != http.StatusOK {
		return nil, fmt.Errorf("non-200 response status: %s", response.Status)
	}

	var containers []dockerContainerJsonResponse
	if err := json.NewDecoder(response.Body).Decode(&containers); err != nil {
		return nil, fmt.Errorf("decoding response: %w", err)
	}

	for i := range containers {

View on GitHub (pinned to 91324e8de7)

Solutions

  1. Validate the tcp:// source host (no spaces; bracket IPv6 literals as [::1]:2375)
  2. Use an IPv4 address or DNS name for the remote Docker host

Example fix

# before
  host: tcp://::1:2375
# after
  host: "tcp://[::1]:2375"
Defensive patterns

Strategy: validation

Validate before calling

if net.ParseIP(hostname) == nil && strings.ContainsAny(hostname, " \t") {
    return fmt.Errorf("invalid docker hostname %q", hostname)
}

Prevention

When it happens

Trigger: hostname contains a space, control character, or invalid bracket syntax (e.g. IPv6 literal not bracketed) coming from a tcp:// source URL.

Common situations: IPv6 remote Docker host written without brackets; garbage host from a mis-templated configuration.

Related errors


AI-assisted analysis of glanceapp/glance@91324e8de7 (2026-08-15). Data as JSON: /api/errors/82ed56cd0715eeb3. Report an issue: GitHub.