grafana/k6 · error

record length ( ) doesn't match header length ( )

Error message

record length (%d) doesn't match header length (%d)

What it means

Raised in Reader.Read when asObjects maps a row to its header: the record's field count differs from the header's column count, so values cannot be paired with column names. Usually caused by ragged rows or a malformed quoting in the data.

Solutions

  1. Make every data row have the same number of fields as the header
  2. Fix quoting/escaping so multi-line or comma-containing fields parse as one column
  3. Remove or repair the offending row indicated by the current line counter
Defensive patterns

Strategy: validation

When it happens

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

Appendix: source

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

	if toLineSet && r.options.ToLine.Int64 > 0 && r.currentLine.Load() > r.options.ToLine.Int64 {
		return nil, io.EOF
	}

	record, err := r.csv.Read()
	if err != nil {
		return nil, err
	}

	r.currentLine.Add(1)

	// If header option is enabled, return a map of the record.
	if r.options.AsObjects.Valid && r.options.AsObjects.Bool {
		if r.columnNames == nil {
			return nil, fmt.Errorf("the 'asObjects' option is enabled, but no header was found")
		}

		if len(record) != len(r.columnNames) {
			return nil, fmt.Errorf("record length (%d) doesn't match header length (%d)", len(record), len(r.columnNames))
		}

		recordMap := make(map[string]string)
		for i, value := range record {
			recordMap[r.columnNames[i]] = value
		}

		return recordMap, nil
	}

	return record, nil
}

// validateOptions validates the reader options and returns an error if any validation fails.
func validateOptions(options options) error {
	var (
		fromLineSet      = options.FromLine.Valid
		toLineSet        = options.ToLine.Valid

View on GitHub (pinned to 01ffac6f24)