{"record":{"id":"7baded1a66495b5f","repo":"grafana/k6","slug":"the-header-option-cannot-be-enabled-when-fromli","errorCode":null,"errorMessage":"the 'header' option cannot be enabled when 'fromLine' is set to a value greater than 0","messagePattern":"the 'header' option cannot be enabled when 'fromLine' is set to a value greater than 0","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/experimental/csv/reader.go","lineNumber":145,"sourceCode":"\n\treturn record, nil\n}\n\n// validateOptions validates the reader options and returns an error if any validation fails.\nfunc validateOptions(options options) error {\n\tvar (\n\t\tfromLineSet      = options.FromLine.Valid\n\t\ttoLineSet        = options.ToLine.Valid\n\t\tskipFirstLineSet = options.SkipFirstLine\n\t\tasObjectsEnabled = options.AsObjects.Valid && options.AsObjects.Bool\n\t)\n\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","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/experimental/csv/reader.go#L127-L163","documentation":"Thrown by k6's experimental CSV module (k6/experimental/csv) when a Parser is constructed or csv.parse() is called with the asObjects option enabled (the message calls it 'header') together with fromLine set to a value greater than 0. When asObjects is on, NewReaderFrom unconditionally consumes the first physical line as the column-name header, so a fromLine that skips past line 0 would make header semantics ambiguous; validateOptions() rejects the combination up front (internal/js/modules/k6/experimental/csv/reader.go:144). Via the JS APIs the error is wrapped as 'failed to create a new parser; reason: ...' before any row is read.","triggerScenarios":"Calling `new csv.Parser(file, { asObjects: true, fromLine: 1 })` or `csv.parse(file, { asObjects: true, fromLine: 3 })` - any call where asObjects is truthy and fromLine is present and > 0.","commonSituations":"Scripts ported from CSV libraries where fromLine is 1-based: developers set fromLine: 1 meaning 'start at the first data row'. Also attempts to skip a preamble/comment block at the top of a file while still getting rows as objects keyed by header names.","solutions":["Drop the fromLine option (or set it to 0): with asObjects: true the header line is consumed automatically and data rows start right after it","If you must skip leading lines, remove asObjects: true and consume rows as arrays, skipping rows in plain JS","Restructure the CSV so the header is the first physical line and the rows you want follow it"],"exampleFix":"// before\nconst parser = new csv.Parser(file, { asObjects: true, fromLine: 1 });\n\n// after\nconst parser = new csv.Parser(file, { asObjects: true });","handlingStrategy":"validation","validationCode":"function assertCsvOptions(o) {\n  if (o.asObjects && o.fromLine !== undefined && o.fromLine > 0) {\n    throw new Error(`asObjects needs the header on line 0; got fromLine=${o.fromLine}. Remove fromLine or preprocess the file.`);\n  }\n  return o;\n}\nconst parser = new csv.Parser(file, assertCsvOptions({ asObjects: true, fromLine: 1 }));","typeGuard":null,"tryCatchPattern":"try {\n  const parser = new csv.Parser(file, opts);\n} catch (e) {\n  if (/header.*option.*fromLine/.test(e.message)) { /* drop fromLine and rebuild opts */ }\n  throw e;\n}","preventionTips":["Treat fromLine as 0-based; only 0 or unset is compatible with asObjects","Route all CSV options through one validated config helper before csv.parse/Parser"],"tags":["csv","k6","options","validation","experimental"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}