{"record":{"id":"c9ef186c30e327cc","repo":"grafana/k6","slug":"the-fromline-option-must-be-less-than-the-tolin","errorCode":null,"errorMessage":"the 'fromLine' option must be less than the 'toLine' option; got 'fromLine': %d, 'toLine': %d","messagePattern":"the 'fromLine' option must be less than the 'toLine' option; got 'fromLine': (.+?), 'toLine': (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/experimental/csv/reader.go","lineNumber":157,"sourceCode":"\n\tif asObjectsEnabled && skipFirstLineSet {\n\t\treturn fmt.Errorf(\"the 'header' option cannot be enabled when 'skipFirstLine' is true\")\n\t}\n\n\tif asObjectsEnabled && fromLineSet && options.FromLine.Int64 > 0 {\n\t\treturn fmt.Errorf(\"the 'header' option cannot be enabled when 'fromLine' is set to a value greater than 0\")\n\t}\n\n\tif fromLineSet && options.FromLine.Int64 < 0 {\n\t\treturn fmt.Errorf(\"the 'fromLine' option must be greater than or equal to 0; got %d\", options.FromLine.Int64)\n\t}\n\n\tif toLineSet && options.ToLine.Int64 < 0 {\n\t\treturn fmt.Errorf(\"the 'toLine' option must be greater than or equal to 0; got %d\", options.ToLine.Int64)\n\t}\n\n\tif fromLineSet && toLineSet && options.FromLine.Int64 >= options.ToLine.Int64 {\n\t\treturn fmt.Errorf(\n\t\t\t\"the 'fromLine' option must be less than the 'toLine' option; got 'fromLine': %d, 'toLine': %d\",\n\t\t\toptions.FromLine.Int64, options.ToLine.Int64,\n\t\t)\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":139,"sourceCodeEnd":165,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/experimental/csv/reader.go#L139-L165","documentation":"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.","triggerScenarios":"`{ fromLine: 5, toLine: 5 }` or `{ fromLine: 10, toLine: 2 }` passed to new csv.Parser() or csv.parse().","commonSituations":"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.","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"],"exampleFix":"// before\nconst parser = new csv.Parser(file, { fromLine: 5, toLine: 5 }); // error: empty window\n\n// after\nconst parser = new csv.Parser(file, { fromLine: 5, toLine: 6 }); // reads exactly line 5","handlingStrategy":"validation","validationCode":"function assertWindow(o) {\n  if (o.fromLine !== undefined && o.toLine !== undefined && o.fromLine >= o.toLine) {\n    throw new Error(`fromLine (${o.fromLine}) must be strictly less than toLine (${o.toLine})`);\n  }\n  return o;\n}\nconst parser = new csv.Parser(file, assertWindow({ fromLine: f, toLine: t }));","typeGuard":null,"tryCatchPattern":"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; }","preventionTips":["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"],"tags":["csv","k6","validation","range"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}