grafana/k6 · error

segment start(%s) must be less than its end(%s)

Error message

segment start(%s) must be less than its end(%s)

What it means

NewExecutionSegment rejected a segment whose start is not strictly less than its end (from >= to). It is the second boundary check of 0 <= from < to <= 1 — the segment would have zero or negative length, making VU striping math invalid.

Source

Thrown at lib/execution_segment.go:54

	_ encoding.TextUnmarshaler = &ExecutionSegment{}
	_ fmt.Stringer             = &ExecutionSegment{}
)

// Helpful "constants" so we don't initialize them in every function call
var (
	zeroRat, oneRat      = big.NewRat(0, 1), big.NewRat(1, 1) //nolint:gochecknoglobals
	oneBigInt, twoBigInt = big.NewInt(1), big.NewInt(2)       //nolint:gochecknoglobals
)

// NewExecutionSegment validates the supplied arguments (basically, that 0 <=
// from < to <= 1) and either returns an error, or it returns a
// fully-initialized and usable execution segment.
func NewExecutionSegment(from, to *big.Rat) (*ExecutionSegment, error) {
	if from.Cmp(zeroRat) < 0 {
		return nil, fmt.Errorf("segment start value must be at least 0 but was %s", from.FloatString(2))
	}
	if from.Cmp(to) >= 0 {
		return nil, fmt.Errorf("segment start(%s) must be less than its end(%s)", from.FloatString(2), to.FloatString(2))
	}
	if to.Cmp(oneRat) > 0 {
		return nil, fmt.Errorf("segment end value can't be more than 1 but was %s", to.FloatString(2))
	}
	return newExecutionSegment(from, to), nil
}

// newExecutionSegment just creates an ExecutionSegment without validating the arguments
func newExecutionSegment(from, to *big.Rat) *ExecutionSegment {
	return &ExecutionSegment{
		from:   from,
		to:     to,
		length: new(big.Rat).Sub(to, from),
	}
}

// stringToRat is a helper function that tries to convert a string to a rational
// number while allowing percentage, decimal, and fraction values.

View on GitHub (pinned to 01ffac6f24)

Solutions

  1. Write the segment with the smaller point first, e.g. 1/2:1 not 1:1/2
  2. Remember the empty 100% segment is written as 0:1, and a lone value like 1/2 means 1/2:1
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at lib/execution_segment.go:54 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/fe3f1310d21e820a. Report an issue: GitHub.