grafana/k6 · error

the reader cannot be nil

Error message

the reader cannot be nil

What it means

Defensive guard in NewReaderFrom: the csv.Reader constructor was called with a nil io.Reader (the r parameter). It is a programmer error in the Go API, not a script-input condition, and fires before any CSV parsing begins.

Source

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

	// options holds the reader's options.
	options options

	// columnNames stores the column names when the asObjects option is enabled
	// in order to be able to map each row values to their corresponding column.
	columnNames []string
}

// NewReaderFrom creates a new CSV reader from the provided io.Reader.
//
// It will check whether the first line should be skipped and consume it if necessary.
// It will also check whether the reader should start from a specific line and skip lines until that line is reached.
// We perform these operations here to avoid having to do them in the Read method.
//
// Hence, this constructor function can return an error if the first line cannot be skipped or if the reader
// cannot start from the specified line.
func NewReaderFrom(r io.Reader, options options) (*Reader, error) {
	if r == nil {
		return nil, fmt.Errorf("the reader cannot be nil")
	}

	if err := validateOptions(options); err != nil {
		return nil, err
	}

	if options.Delimiter == 0 {
		options.Delimiter = ','
	}

	csvParser := csv.NewReader(r)
	csvParser.Comma = options.Delimiter

	reader := &Reader{
		csv:     csvParser,
		options: options,
	}

View on GitHub (pinned to 01ffac6f24)

Solutions

  1. Pass a non-nil io.Reader (e.g. os.File, bytes.Reader, strings.Reader) to NewReaderFrom
  2. Check the reader argument for nil before constructing the Reader
Defensive patterns

Strategy: type-guard

When it happens

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