grafana/k6 · error

the target for stage %d can't be negative

Error message

the target for stage %d can't be negative

What it means

validateStages rejected a stage whose target is negative. Target is set, but VU/iteration-rate levels cannot be below zero; typically a sign error or a bad computed value in a generated stage list.

Source

Thrown at lib/executor/helpers.go:53

// A helper function to avoid code duplication
func validateStages(stages []Stage) []error {
	var errors []error
	if len(stages) == 0 {
		errors = append(errors, fmt.Errorf("at least one stage has to be specified"))
		return errors
	}

	for i, s := range stages {
		stageNum := i + 1
		if !s.Duration.Valid {
			errors = append(errors, fmt.Errorf("stage %d doesn't have a duration", stageNum))
		} else if s.Duration.Duration < 0 {
			errors = append(errors, fmt.Errorf("the duration for stage %d can't be negative", stageNum))
		}
		if !s.Target.Valid {
			errors = append(errors, fmt.Errorf("stage %d doesn't have a target", stageNum))
		} else if s.Target.Int64 < 0 {
			errors = append(errors, fmt.Errorf("the target for stage %d can't be negative", stageNum))
		}
	}
	return errors
}

// handleInterrupt returns true if err is InterruptError and if so it
// cancels the executor context passed with ctx.
func handleInterrupt(ctx context.Context, err error) bool {
	if err != nil {
		if errext.IsInterruptError(err) {
			execution.AbortTestRun(ctx, err)
			return true
		}
	}
	return false
}

// getIterationRunner is a helper function that returns an iteration executor

View on GitHub (pinned to 01ffac6f24)

Solutions

  1. Set target to 0 or a positive integer
  2. Validate generated stage arrays before passing them as options
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at lib/executor/helpers.go:53 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18). Data as JSON: /api/errors/8be3de48186b7f61. Report an issue: GitHub.