grafana/k6 · error

the 'toLine' option must be greater than or equal to 0; got

Error message

the 'toLine' option must be greater than or equal to 0; got %d

What it means

Raised by validateOptions during NewReaderFrom: the toLine option received a negative value. The end-line bound must be zero or positive; the message reports the offending value.

Solutions

  1. Set toLine to 0 or a positive line index
  2. Remove the toLine option to read to end of file
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at internal/js/modules/k6/experimental/csv/reader.go:153 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/62ce36b3951e6286. Report an issue: GitHub.

Appendix: source

Thrown at internal/js/modules/k6/experimental/csv/reader.go:153

		toLineSet        = options.ToLine.Valid
		skipFirstLineSet = options.SkipFirstLine
		asObjectsEnabled = options.AsObjects.Valid && options.AsObjects.Bool
	)

	if asObjectsEnabled && skipFirstLineSet {
		return fmt.Errorf("the 'header' option cannot be enabled when 'skipFirstLine' is true")
	}

	if asObjectsEnabled && fromLineSet && options.FromLine.Int64 > 0 {
		return fmt.Errorf("the 'header' option cannot be enabled when 'fromLine' is set to a value greater than 0")
	}

	if fromLineSet && options.FromLine.Int64 < 0 {
		return fmt.Errorf("the 'fromLine' option must be greater than or equal to 0; got %d", options.FromLine.Int64)
	}

	if toLineSet && options.ToLine.Int64 < 0 {
		return fmt.Errorf("the 'toLine' option must be greater than or equal to 0; got %d", options.ToLine.Int64)
	}

	if fromLineSet && toLineSet && options.FromLine.Int64 >= options.ToLine.Int64 {
		return fmt.Errorf(
			"the 'fromLine' option must be less than the 'toLine' option; got 'fromLine': %d, 'toLine': %d",
			options.FromLine.Int64, options.ToLine.Int64,
		)
	}

	return nil
}

View on GitHub (pinned to 01ffac6f24)