grafana/k6 · error
the 'fromLine' option must be less than the 'toLine' option;
Error message
the 'fromLine' option must be less than the 'toLine' option; got 'fromLine': %d, 'toLine': %d
What it means
The experimental CSV reader requires a non-empty, ordered read window: when both fromLine and toLine are set, fromLine must be strictly less than toLine (internal/js/modules/k6/experimental/csv/reader.go:156). Equality is rejected because fromLine is where reading starts (0-based) and toLine is the inclusive stop, so fromLine == toLine selects zero lines. Note: through the public JS APIs (new csv.Parser / csv.parse) an earlier check in newParserOptionsFrom (module.go:362) usually fires first with the message 'fromLine must be less than or equal to toLine'; the reader-level message is the underlying guard.
Source
Thrown at internal/js/modules/k6/experimental/csv/reader.go:157
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 93accf6570)
Solutions
- Make fromLine strictly smaller than toLine - to read only line 5 use { fromLine: 5, toLine: 6 }
- Convert 1-based inclusive ranges as fromLine = first - 1, toLine = last
- Validate the window in your config layer before constructing the parser
Example fix
// before
const parser = new csv.Parser(file, { fromLine: 5, toLine: 5 }); // error: empty window
// after
const parser = new csv.Parser(file, { fromLine: 5, toLine: 6 }); // reads exactly line 5 Defensive patterns
Strategy: validation
Validate before calling
function assertWindow(o) {
if (o.fromLine !== undefined && o.toLine !== undefined && o.fromLine >= o.toLine) {
throw new Error(`fromLine (${o.fromLine}) must be strictly less than toLine (${o.toLine})`);
}
return o;
}
const parser = new csv.Parser(file, assertWindow({ fromLine: f, toLine: t })); Try / catch
try { new csv.Parser(file, opts); } catch (e) { if (/fromLine.*less than.*toLine|fromLine must be less than/.test(e.message)) { /* recompute bounds, retry */ } throw e; } Prevention
- Remember toLine is inclusive: a one-line window is {fromLine: n, toLine: n+1}
- Compute both bounds from one source of truth and validate ordering before use
When it happens
Trigger: `{ fromLine: 5, toLine: 5 }` or `{ fromLine: 10, toLine: 2 }` passed to new csv.Parser() or csv.parse().
Common situations: Inclusive/exclusive confusion - treating toLine as exclusive and setting it equal to fromLine to read 'exactly one line'; bounds both computed from user input where start can overtake end.
Related errors
- the 'header' option cannot be enabled when 'fromLine' is set
- the 'fromLine' option must be greater than or equal to 0; go
- the 'toLine' option must be greater than or equal to 0; got
- invalid size
- empty name provided to SharedArray's constructor
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/c9ef186c30e327cc.
Report an issue: GitHub.