{"record":{"id":"8b913f516ce13b4d","repo":"grafana/k6","slug":"the-asobjects-option-is-enabled-but-no-header-w","errorCode":null,"errorMessage":"the 'asObjects' option is enabled, but no header was found","messagePattern":"the 'asObjects' option is enabled, but no header was found","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/experimental/csv/reader.go","lineNumber":113,"sourceCode":"func (r *Reader) Read() (any, error) {\n\ttoLineSet := r.options.ToLine.Valid\n\n\t// If the `toLine` option was set and we have reached it, we return EOF.\n\tif toLineSet && r.options.ToLine.Int64 > 0 && r.currentLine.Load() > r.options.ToLine.Int64 {\n\t\treturn nil, io.EOF\n\t}\n\n\trecord, err := r.csv.Read()\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tr.currentLine.Add(1)\n\n\t// If header option is enabled, return a map of the record.\n\tif r.options.AsObjects.Valid && r.options.AsObjects.Bool {\n\t\tif r.columnNames == nil {\n\t\t\treturn nil, fmt.Errorf(\"the 'asObjects' option is enabled, but no header was found\")\n\t\t}\n\n\t\tif len(record) != len(r.columnNames) {\n\t\t\treturn nil, fmt.Errorf(\"record length (%d) doesn't match header length (%d)\", len(record), len(r.columnNames))\n\t\t}\n\n\t\trecordMap := make(map[string]string)\n\t\tfor i, value := range record {\n\t\t\trecordMap[r.columnNames[i]] = value\n\t\t}\n\n\t\treturn recordMap, nil\n\t}\n\n\treturn record, nil\n}\n\n// validateOptions validates the reader options and returns an error if any validation fails.","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/js/modules/k6/experimental/csv/reader.go#L95-L131","documentation":"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.","triggerScenarios":"Thrown at internal/js/modules/k6/experimental/csv/reader.go:113 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure the CSV file begins with a non-empty header line when using asObjects","Check that the file was not truncated or replaced between parser creation and reads","Disable asObjects and work with array rows if no header exists"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"01ffac6f245854c1b8adc6a69857c76a15f90022","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}