{"record":{"id":"2885f7cd842036c9","repo":"grafana/k6","slug":"the-reader-cannot-be-nil","errorCode":null,"errorMessage":"the reader cannot be nil","messagePattern":"the reader cannot be nil","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/experimental/csv/reader.go","lineNumber":39,"sourceCode":"\t// options holds the reader's options.\n\toptions options\n\n\t// columnNames stores the column names when the asObjects option is enabled\n\t// in order to be able to map each row values to their corresponding column.\n\tcolumnNames []string\n}\n\n// NewReaderFrom creates a new CSV reader from the provided io.Reader.\n//\n// It will check whether the first line should be skipped and consume it if necessary.\n// It will also check whether the reader should start from a specific line and skip lines until that line is reached.\n// We perform these operations here to avoid having to do them in the Read method.\n//\n// Hence, this constructor function can return an error if the first line cannot be skipped or if the reader\n// cannot start from the specified line.\nfunc NewReaderFrom(r io.Reader, options options) (*Reader, error) {\n\tif r == nil {\n\t\treturn nil, fmt.Errorf(\"the reader cannot be nil\")\n\t}\n\n\tif err := validateOptions(options); err != nil {\n\t\treturn nil, err\n\t}\n\n\tif options.Delimiter == 0 {\n\t\toptions.Delimiter = ','\n\t}\n\n\tcsvParser := csv.NewReader(r)\n\tcsvParser.Comma = options.Delimiter\n\n\treader := &Reader{\n\t\tcsv:     csvParser,\n\t\toptions: options,\n\t}\n","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/js/modules/k6/experimental/csv/reader.go#L21-L57","documentation":"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.","triggerScenarios":"Thrown at internal/js/modules/k6/experimental/csv/reader.go:39 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass a non-nil io.Reader (e.g. os.File, bytes.Reader, strings.Reader) to NewReaderFrom","Check the reader argument for nil before constructing the Reader"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"01ffac6f245854c1b8adc6a69857c76a15f90022","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}