grafana/k6 · error

the duration for stage %d can't be negative

Error message

the duration for stage %d can't be negative

What it means

validateStages rejected a stage with a negative duration. Duration is set and valid, but a stage cannot last a negative amount of time; likely a typo or a computed value that went below zero.

Source

Thrown at lib/executor/helpers.go:48

		}
	}
	return result
}

// 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
		}

View on GitHub (pinned to 01ffac6f24)

Solutions

  1. Use a non-negative duration string like '1m'
  2. Check programmatically generated stage lists for sign errors
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at lib/executor/helpers.go:48 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/4273f9cb72c8b10a. Report an issue: GitHub.