tsenart/vegeta · error
bad URL: %s, %w
Error message
bad URL: %s, %w
What it means
Returned when the URL portion of a target line fails url.ParseRequestURI. The method was valid but the second token is not a parseable absolute request URI.
Source
Thrown at lib/targets.go:300
}
}
tgt.Body = body
tgt.Header = http.Header{}
for k, vs := range hdr {
tgt.Header[k] = vs
}
tokens := strings.SplitN(line, " ", 2)
if len(tokens) < 2 {
return fmt.Errorf("bad target: %s", line)
}
if !startsWithHTTPMethod(line) {
return fmt.Errorf("bad method: %s", tokens[0])
}
tgt.Method = tokens[0]
if _, err = url.ParseRequestURI(tokens[1]); err != nil {
return fmt.Errorf("bad URL: %s, %w", tokens[1], err)
}
tgt.URL = tokens[1]
line = strings.TrimSpace(sc.Peek())
if line == "" || startsWithHTTPMethod(line) {
return nil
}
for sc.Scan() {
if line = strings.TrimSpace(sc.Text()); line == "" {
break
} else if strings.HasPrefix(line, "#") {
continue
} else if strings.HasPrefix(line, "@") {
if tgt.Body, err = os.ReadFile(line[1:]); err != nil {
return fmt.Errorf("bad body: %w", err)
}
break
}
tokens = strings.SplitN(line, ":", 2)View on GitHub (pinned to cf58112690)
Solutions
- Provide an absolute URL including scheme and host, e.g. "GET http://localhost:8080/path".
- Percent-encode or quote special characters in the URL.
- Inspect the URL text shown in the error and run it through url.ParseRequestURI locally to confirm validity.
- Shell-quote URLs containing ? and & so the targets file ends up intact.
Example fix
// before GET localhost:8080/hello?a=1&b=2 // after GET http://localhost:8080/hello?a=1&b=2
Defensive patterns
Strategy: validation
Validate before calling
func validURL(u string) error {
_, err := url.ParseRequestURI(u)
return err
}
// ensure scheme present
func hasScheme(u string) bool { return strings.HasPrefix(u, "http://") || strings.HasPrefix(u, "https://") } Try / catch
if _, err := vegeta.NewTargets(r); err != nil {
if strings.Contains(err.Error(), "bad URL:") {
return fmt.Errorf("targets need absolute http(s) URLs: %w", err)
}
return err
} Prevention
- Always include scheme and host in target URLs.
- Quote URLs with special chars (?, &, #) in scripts.
- Reject relative paths in targets files during linting.
When it happens
Trigger: Target lines with malformed URLs: missing scheme ("GET localhost:8080/"), invalid characters or spaces in the URL, or an empty URL token.
Common situations: Writing relative paths instead of absolute URLs in targets files, unencoded special characters (#, spaces, quotes) in URLs, shell variable expansion gone wrong leaving "" or partial URLs.
Related errors
AI-assisted analysis of tsenart/vegeta@cf58112690 (2026-08-31).
Data as JSON: /api/errors/74c43575c751201b.
Report an issue: GitHub.