wtfutil/wtf · error

invalid URL: %w

Error message

invalid URL: %w

What it means

After the URL passes the empty check, parseURL calls url.Parse. 'invalid URL: %w' wraps any parsing error returned by net/url.Parse — meaning the configured string is not a syntactically valid absolute URL (bad scheme, control characters, malformed percent-encoding, etc.). The %w wrap preserves the underlying url.Parse error.

Source

Thrown at modules/uptimekuma/widget.go:222

	}
	defer func() { _ = resp.Body.Close() }()

	var data HeartbeatData
	if err := json.NewDecoder(resp.Body).Decode(&data); err != nil {
		return nil, err
	}

	return &data, nil
}

func parseURL(rawURL string) (string, string, error) {
	if rawURL == "" {
		return "", "", fmt.Errorf("URL is not defined")
	}

	u, err := url.Parse(rawURL)
	if err != nil {
		return "", "", fmt.Errorf("invalid URL: %w", err)
	}

	parts := strings.Split(strings.Trim(u.Path, "/"), "/")
	if len(parts) < 2 || parts[0] != "status" {
		return "", "", fmt.Errorf("invalid status page URL format. Expected '.../status/<slug>'")
	}

	slug := parts[1]
	baseURL := fmt.Sprintf("%s://%s", u.Scheme, u.Host)

	return baseURL, slug, nil
}

View on GitHub (pinned to bb838c1ccb)

Solutions

  1. Inspect the wrapped cause after '%!' to see the exact url.Parse complaint and fix that character/portion of the URL
  2. Ensure the URL includes a valid scheme and host, e.g. https://uptime.example.com/status/main
  3. Quote the value in YAML (url: "...") to avoid special-character parsing issues, and trim whitespace

Example fix

// before
url: https://uptime.example.com/status/main 
// after
url: "https://uptime.example.com/status/main"
Defensive patterns

Strategy: validation

Validate before calling

u, err := url.Parse(cfg.URL)
if err != nil {
    return fmt.Errorf("uptimekuma url invalid: %w", err)
}
if u.Scheme == "" || u.Host == "" {
    return fmt.Errorf("uptimekuma url must be absolute with scheme and host")
}

Prevention

When it happens

Trigger: Refresh calls parseURL with a configured URL string that url.Parse rejects — e.g. url: "ht!tp://foo", a URL containing spaces or unescaped special characters, or a garbage non-URL string.

Common situations: Typo'd scheme, pasting a URL with trailing spaces or invisible characters from documentation, missing scheme combined with characters url.Parse treats as invalid, quoting mistakes in YAML that inject stray characters.

Understand the failure class

Background: "Invalid URL" errors: why new URL(), URI.parse, and reqwest::Url reject your string — missing scheme, whitespace, and bad path format — this error's family across 39 libraries.

Related errors


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