grafana/k6 · error

the 'asObjects' option is enabled, but no header was found

Error message

the 'asObjects' option is enabled, but no header was found

What it means

Raised in Reader.Read when the asObjects option is enabled but the reader has no stored column names, because the header was never consumed — typically the file was empty at construction time or internal state was mutated.

Solutions

  1. Ensure the CSV file begins with a non-empty header line when using asObjects
  2. Check that the file was not truncated or replaced between parser creation and reads
  3. Disable asObjects and work with array rows if no header exists
Defensive patterns

Strategy: validation

When it happens

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

Appendix: source

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

func (r *Reader) Read() (any, error) {
	toLineSet := r.options.ToLine.Valid

	// If the `toLine` option was set and we have reached it, we return EOF.
	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.

View on GitHub (pinned to 01ffac6f24)