{"record":{"id":"2c0e6bb3e2590a66","repo":"grafana/k6","slug":"failed-to-marshal-record-reason-w","errorCode":null,"errorMessage":"failed to marshal record; reason: %w","messagePattern":"failed to marshal record; reason: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/data/data.go","lineNumber":148,"sourceCode":"\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\n\treturn func() *sobek.Object {\n\t\treturn array.wrap(rt).ToObject(rt)\n\t}, nil\n}\n","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/js/modules/k6/data/data.go#L130-L166","documentation":"Raised inside the SharedArray builder when json.Marshal fails on a single record read from the RecordReader ('%w' carries the marshal error). Records must be JSON-serializable to be stored as strings in the shared array; this fires when a record contains types Go cannot marshal (channels, functions, NaN floats, cyclic structures) — a data-shape problem in the record itself, not a read failure (reads have their own wrap).","triggerScenarios":"Thrown at internal/js/modules/k6/data/data.go:148 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure every record contains only JSON-serializable values (strings, numbers, booleans, plain objects/arrays)","Replace NaN/Infinity floats with null or concrete numbers","Avoid exotic types in the reader's output records","Inspect the wrapped marshal error to identify the offending field"],"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"}