{"record":{"id":"521842f96b0f9e77","repo":"grafana/k6","slug":"sharedarray-is-immutable","errorCode":null,"errorMessage":"SharedArray is immutable","messagePattern":"SharedArray is immutable","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/data/share.go","lineNumber":37,"sourceCode":"\tisFrozen sobek.Callable\n\tparse    sobek.Callable\n}\n\nfunc (s sharedArray) wrap(rt *sobek.Runtime) sobek.Value {\n\tfreeze, _ := sobek.AssertFunction(rt.GlobalObject().Get(\"Object\").ToObject(rt).Get(\"freeze\"))\n\tisFrozen, _ := sobek.AssertFunction(rt.GlobalObject().Get(\"Object\").ToObject(rt).Get(\"isFrozen\"))\n\tparse, _ := sobek.AssertFunction(rt.GlobalObject().Get(\"JSON\").ToObject(rt).Get(\"parse\"))\n\treturn rt.NewDynamicArray(wrappedSharedArray{\n\t\tsharedArray: s,\n\t\trt:          rt,\n\t\tfreeze:      freeze,\n\t\tisFrozen:    isFrozen,\n\t\tparse:       parse,\n\t})\n}\n\nfunc (s wrappedSharedArray) Set(_ int, _ sobek.Value) bool {\n\tpanic(s.rt.NewTypeError(\"SharedArray is immutable\")) // this is specifically a type error\n}\n\nfunc (s wrappedSharedArray) SetLen(_ int) bool {\n\tpanic(s.rt.NewTypeError(\"SharedArray is immutable\")) // this is specifically a type error\n}\n\nfunc (s wrappedSharedArray) Get(index int) sobek.Value {\n\tif index < 0 || index >= len(s.arr) {\n\t\treturn sobek.Undefined()\n\t}\n\tval, err := s.parse(sobek.Undefined(), s.rt.ToValue(s.arr[index]))\n\tif err != nil {\n\t\tcommon.Throw(s.rt, err)\n\t}\n\n\terr = s.deepFreeze(s.rt, val)\n\tif err != nil {\n\t\tcommon.Throw(s.rt, err)","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/js/modules/k6/data/share.go#L19-L55","documentation":"An attempt to write into a SharedArray was rejected. SharedArray contents are frozen and shared read-only across all VUs for memory efficiency; the underlying wrappedSharedArray.Set is a guard that blocks mutation, since writes would be either VU-local lies or racy.","triggerScenarios":"Thrown at internal/js/modules/k6/data/share.go:37 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Do not assign to elements of a SharedArray; copy the data out first (e.g. const item = {...shared[i]}) and modify the copy","If per-VU mutable state is needed, use a regular array or a per-VU variable","Precompute any transformed data before building the SharedArray"],"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":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}