{"record":{"id":"9cf2befa16381fdb","repo":"grafana/k6","slug":"failed-to-read-record-reason-w","errorCode":null,"errorMessage":"failed to read record; reason: %w","messagePattern":"failed to read record; reason: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/data/data.go","lineNumber":143,"sourceCode":"// The r argument is a [RecordReader] from which records are read and stored in the shared array.\nfunc (d *Data) NewSharedArrayFrom(rt *sobek.Runtime, name string, r RecordReader) (func() *sobek.Object, error) {\n\tif name == \"\" {\n\t\treturn nil, errors.New(\"empty name provided to SharedArray's constructor\")\n\t}\n\n\t// The builder function is passed to loadOrStore, which ensures it is only\n\t// executed once for a given name. This guarantees the underlying data is\n\t// initialized exactly once, even if multiple VUs call this function concurrently\n\t// with the same name.\n\tbuilder := func() (sharedArray, error) {\n\t\tvar arr []string\n\t\tfor {\n\t\t\trecord, err := r.Read()\n\t\t\tif errors.Is(err, io.EOF) {\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tif err != nil {\n\t\t\t\treturn sharedArray{}, fmt.Errorf(\"failed to read record; reason: %w\", err)\n\t\t\t}\n\n\t\t\tmarshaled, err := json.Marshal(record)\n\t\t\tif err != nil {\n\t\t\t\treturn sharedArray{}, fmt.Errorf(\"failed to marshal record; reason: %w\", err)\n\t\t\t}\n\n\t\t\tarr = append(arr, string(marshaled))\n\t\t}\n\n\t\treturn sharedArray{arr: arr}, nil\n\t}\n\n\tarray, err := d.shared.loadOrStore(name, builder)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/js/modules/k6/data/data.go#L125-L161","documentation":"Raised inside the SharedArray builder in NewSharedArrayFrom when the RecordReader's Read() returns an error other than io.EOF while filling the shared array. The input at fault is the underlying data source (e.g. a parsed file); the wrapped error explains the read failure, such as malformed rows, encoding problems, or an interrupted stream. Because the builder runs once under loadOrStore, this aborts shared-array construction for all VUs.","triggerScenarios":"Thrown at internal/js/modules/k6/data/data.go:143 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check the underlying data source for corruption or encoding issues","Validate the file is readable and correctly formatted for its reader type","Look at the wrapped error for the reader-specific cause","Fix the data file and re-run; the array is built only once per name"],"exampleFix":null,"handlingStrategy":"try-catch","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-14T00:17:10.932Z"}