tsenart/vegeta · error
ErrNilTarget
ErrNilTarget
Error message
nil target
What it means
ErrNilTarget is returned when a Targeter yields a nil *Target pointer. The attacker requires a fully allocated Target to issue a request, so a nil pointer is rejected defensively.
Source
Thrown at lib/targets.go:93
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
- Fix the custom Targeter to allocate and populate the target: *tgt = &vegeta.Target{...} before returning nil.
- Return a descriptive error from your Targeter instead of nil target + nil error.
- Check for nil target inside your targeter and skip/log such entries.
Example fix
// before
func(tgt *vegeta.Target) error { return nil }
// after
func(tgt *vegeta.Target) error {
if tgt == nil { return errors.New("nil target out-param") }
*tgt = vegeta.Target{Method: "GET", URL: "http://localhost/"}
return nil
} Defensive patterns
Strategy: type-guard
Type guard
func validTarget(t *vegeta.Target) bool {
return t != nil && t.Method != "" && t.URL != ""
} Try / catch
if t, err := targeter(&tr); err != nil {
return err
} else if t == nil {
return vegeta.ErrNilTarget
} Prevention
- In custom Targeters, always allocate the out Target before returning nil
- Never return (nil, nil) from a Targeter
- Unit-test custom targeters against the nil-target case
When it happens
Trigger: A custom Targeter func writing nothing into the *Target out-parameter (or returning a nil target) while returning nil error; JSON/HTTP targeters encountering nil entries in their pipelines.
Common situations: Hand-written Targeter wrappers that forget to populate the out param, decoding into a nil pointer, or test fixtures with missing entries.
Related errors
AI-assisted analysis of tsenart/vegeta@cf58112690 (2026-08-31).
Data as JSON: /api/errors/9c23a555a59fde22.
Report an issue: GitHub.