tsenart/vegeta · error

bad target: %s

Error message

bad target: %s

What it means

Returned by vegeta's targets parser (NewIntegerTargets/encoder decoding) when a target definition line does not contain a METHOD and URL separated by a space. The line is split on the first space; fewer than two tokens means no URL was supplied.

Source

Thrown at lib/targets.go:293

			if !sc.Scan() {
				return ErrNoTargets
			}
			line = strings.TrimSpace(sc.Text())

			if len(line) != 0 && line[0] != '#' {
				break
			}
		}

		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

View on GitHub (pinned to cf58112690)

Solutions

  1. Ensure every target line has the form "METHOD URL", e.g. "GET http://localhost:8080/".
  2. Prefix any comment lines with '#' so they are skipped.
  3. Strip trailing carriage returns (dos2unix) or ensure the URL isn't on a separate line from the method.
  4. Check the exact offending line printed in the error and fix it in the targets file.

Example fix

// before (targets.txt)
GET
// after
GET http://localhost:8080/
Defensive patterns

Strategy: validation

Validate before calling

func validTargetLine(line string) bool {
    parts := strings.SplitN(line, " ", 2)
    return len(parts) == 2 && strings.TrimSpace(parts[1]) != "" &&
        !strings.HasPrefix(line, "#")
}

Try / catch

tgt, err := vegeta.NewTargetsFromFile(path)
if err != nil && strings.HasPrefix(err.Error(), "bad target:") {
    return fmt.Errorf("targets file %s: every line needs 'METHOD URL': %w", path, err)
}

Prevention

When it happens

Trigger: Parsing a targets file/line that lacks a URL, e.g. a line containing only "GET", an empty-ish line with stray whitespace, or a line that is a comment/comment-like text without '#'.

Common situations: Hand-written targets.txt with missing URLs, CRLF line endings mangling lines, accidentally pasting headers before the first request line, or using a description line without a leading '#'.

Related errors


AI-assisted analysis of tsenart/vegeta@cf58112690 (2026-08-31). Data as JSON: /api/errors/e7879b2584a89eed. Report an issue: GitHub.