tsenart/vegeta · error

ErrNoTargets

ErrNoTargets

Error message

no targets to attack

What it means

ErrNoTargets is returned by targeters (ReadAllTargets, HTTP/JSON targeters) when not enough Targets are available to run an attack. Vegeta refuses to attack an empty target set.

Source

Thrown at lib/targets.go:91

		for k := range t.Header {
			left, right := t.Header[k], other.Header[k]
			if len(left) != len(right) {
				return false
			}
			for i := range left {
				if left[i] != right[i] {
					return false
				}
			}
		}

		return true
	}
}

var (
	// ErrNoTargets is returned when not enough Targets are available.
	ErrNoTargets = errors.New("no targets to attack")
	// ErrNilTarget is returned when the passed Target pointer is nil.
	ErrNilTarget = errors.New("nil target")
	// ErrNoMethod is returned by JSONTargeter when a parsed Target has
	// no method.
	ErrNoMethod = errors.New("target: required method is missing")
	// ErrNoURL is returned by JSONTargeter when a parsed Target has no
	// URL.
	ErrNoURL = errors.New("target: required url is missing")
	// TargetFormats contains the canonical list of the valid target
	// format identifiers.
	TargetFormats = []string{HTTPTargetFormat, JSONTargetFormat}
)

const (
	// HTTPTargetFormat is the human readable identifier for the HTTP target format.
	HTTPTargetFormat = "http"
	// JSONTargetFormat is the human readable identifier for the JSON target format.
	JSONTargetFormat = "json"

View on GitHub (pinned to cf58112690)

Solutions

  1. Provide a non-empty targets file, e.g. lines like `GET http://localhost:8080/`.
  2. Verify the path passed to -targets/ReadAllTargets points to the intended file and is readable.
  3. Check target format flag matches the file content (http vs json).

Example fix

// before
cat /dev/null | vegeta attack > results.bin  // empty targets
// after
printf 'GET http://localhost:8080/\n' > targets.txt
vegeta attack -targets targets.txt > results.bin
Defensive patterns

Strategy: validation

Validate before calling

fi, err := os.Stat(targetsPath)
if err != nil || fi.Size() == 0 {
    return errors.New("targets file missing or empty")
}

Try / catch

if err := vegeta.ReadAllTargets(reader, format, &targets); err != nil {
    if errors.Is(err, vegeta.ErrNoTargets) {
        log.Fatal("no targets: check your -targets file and format flag")
    }
    return err
}

Prevention

When it happens

Trigger: ReadAllTargets hitting EOF before reading a single target; an empty/blank targets file; JSON target stream with no target objects; NewHTTPTargeter with a reader producing nothing.

Common situations: Empty targets.txt passed to `vegeta attack -targets`, wrong file path silently resolving to empty, line endings/format issues causing the parser to yield zero targets, or a JSON file containing only whitespace.

Related errors


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