grafana/k6 · error
failed to read record; reason: %w
Error message
failed to read record; reason: %w
What it means
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.
Source
Thrown at internal/js/modules/k6/data/data.go:143
// The r argument is a [RecordReader] from which records are read and stored in the shared array.
func (d *Data) NewSharedArrayFrom(rt *sobek.Runtime, name string, r RecordReader) (func() *sobek.Object, error) {
if name == "" {
return nil, errors.New("empty name provided to SharedArray's constructor")
}
// The builder function is passed to loadOrStore, which ensures it is only
// executed once for a given name. This guarantees the underlying data is
// initialized exactly once, even if multiple VUs call this function concurrently
// with the same name.
builder := func() (sharedArray, error) {
var arr []string
for {
record, err := r.Read()
if errors.Is(err, io.EOF) {
break
}
if err != nil {
return sharedArray{}, fmt.Errorf("failed to read record; reason: %w", err)
}
marshaled, err := json.Marshal(record)
if err != nil {
return sharedArray{}, fmt.Errorf("failed to marshal record; reason: %w", err)
}
arr = append(arr, string(marshaled))
}
return sharedArray{arr: arr}, nil
}
array, err := d.shared.loadOrStore(name, builder)
if err != nil {
return nil, err
}
View on GitHub (pinned to 01ffac6f24)
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
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at internal/js/modules/k6/data/data.go:143 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/9cf2befa16381fdb.
Report an issue: GitHub.