grafana/k6 · error

threshold %d run error: %w

Error message

threshold %d run error: %w

What it means

During Thresholds.runAll, one Threshold.run invocation on the sinked values returned an error, so the whole threshold evaluation aborts and is wrapped with the index of the offending threshold. The underlying error is most often the invalid-operator guard from Threshold.runNoTaint; the index identifies which thresholds[i] failed.

Source

Thrown at metrics/thresholds.go:150

func newThresholdsWithConfig(configs []thresholdConfig) Thresholds {
	thresholds := make([]*Threshold, len(configs))
	sinked := make(map[string]float64)

	for i, config := range configs {
		t := newThreshold(config.Threshold, config.AbortOnFail, config.AbortGracePeriod)
		thresholds[i] = t
	}

	return Thresholds{thresholds, false, sinked}
}

func (ts *Thresholds) runAll(timeSpentInTest time.Duration) (bool, error) {
	succeeded := true
	for i, threshold := range ts.Thresholds {
		b, err := threshold.run(ts.sinked)
		if err != nil {
			return false, fmt.Errorf("threshold %d run error: %w", i, err)
		}

		if !b {
			succeeded = false

			if ts.Abort || !threshold.AbortOnFail {
				continue
			}

			ts.Abort = !threshold.AbortGracePeriod.Valid ||
				threshold.AbortGracePeriod.Duration < types.Duration(timeSpentInTest)
		}
	}

	return succeeded, nil
}

// Run processes all the thresholds with the provided Sink at the provided time and returns if any

View on GitHub (pinned to 01ffac6f24)

Solutions

  1. Look at the thresholds list in your options at the reported index and fix or remove that threshold expression
  2. Check the wrapped error chain to identify the root cause (usually an invalid operator)
  3. Update k6 if running an old version where operator parsing and evaluation were inconsistent
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at metrics/thresholds.go:150 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/20dc2cfd6f29ecd4. Report an issue: GitHub.