grafana/k6 · error

maxRetries must be non-negative

Error message

maxRetries must be non-negative

What it means

validateConfig() checks that maxRetries for the url secret source is not negative. Unlike the other numeric fields, 0 is a legal value (meaning 'do not retry'), so only values below zero are rejected. The error surfaces at startup during config validation.

Source

Thrown at internal/secretsource/url/url.go:595

	// Validate required fields and value constraints
	if err := validateURLTemplate(config.URLTemplate); err != nil {
		return err
	}

	if config.Timeout.Duration <= 0 {
		return errors.New("timeout must be greater than 0")
	}

	if config.RequestsPerMinuteLimit.Int64 <= 0 {
		return errors.New("requestsPerMinuteLimit must be greater than 0")
	}

	if config.RequestsBurst.Int64 <= 0 {
		return errors.New("requestsBurst must be greater than 0")
	}

	if config.MaxRetries.Int64 < 0 {
		return errors.New("maxRetries must be non-negative")
	}

	if config.RetryBackoff.Duration <= 0 {
		return errors.New("retryBackoff must be greater than 0")
	}

	return nil
}

View on GitHub (pinned to 93accf6570)

Solutions

  1. Set maxRetries to 0 to disable retries, or to a small positive number such as 3
  2. Check the sign of computed values before exporting them to env vars
  3. Remember the field counts retries, not total attempts

Example fix

# before
K6_SECRET_SOURCE_URL_MAX_RETRIES='-1'

# after
K6_SECRET_SOURCE_URL_MAX_RETRIES='0'
Defensive patterns

Strategy: validation

Validate before calling

const retries = Number(process.env.K6_SECRET_SOURCE_URL_MAX_RETRIES);
if (process.env.K6_SECRET_SOURCE_URL_MAX_RETRIES && retries < 0) {
  throw new Error('maxRetries must be >= 0');
}

Prevention

When it happens

Trigger: Setting K6_SECRET_SOURCE_URL_MAX_RETRIES='-1' (or any negative integer), or "maxRetries": -3 in the JSON/inline config.

Common situations: Using -1 as an 'infinite retries' convention from other tools; sign errors when computing the value; flipping the meaning of the field ('retries' vs 'attempts').

Related errors


AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15). Data as JSON: /api/errors/c61dbb771db4437e. Report an issue: GitHub.