{"record":{"id":"61b3116a0cd59c78","repo":"grafana/k6","slug":"failed-to-encode-the-lib-options-as-json-w","errorCode":null,"errorMessage":"failed to encode the lib.Options as json: %w","messagePattern":"failed to encode the lib\\.Options as json: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/execution/execution.go","lineNumber":299,"sourceCode":"\tfor p, get := range props {\n\t\terr := o.DefineAccessorProperty(p, rt.ToValue(get), nil, sobek.FLAG_FALSE, sobek.FLAG_TRUE)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t}\n\n\treturn o, nil\n}\n\n// optionsAsObject maps the lib.Options struct that contains the consolidated\n// and derived options configuration in a sobek.Object.\n//\n// When values are not set then the default value returned from JSON is used.\n// Most of the lib.Options are Nullable types so they will be null on default.\nfunc optionsAsObject(rt *sobek.Runtime, options lib.Options) (*sobek.Object, error) {\n\tb, err := json.Marshal(options)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to encode the lib.Options as json: %w\", err)\n\t}\n\n\t// Using the native JS parser function guarantees getting\n\t// the supported types for deep freezing the complex object.\n\tjsonParse, _ := sobek.AssertFunction(rt.GlobalObject().Get(\"JSON\").ToObject(rt).Get(\"parse\"))\n\tparsed, err := jsonParse(sobek.Undefined(), rt.ToValue(string(b)))\n\tif err != nil {\n\t\tcommon.Throw(rt, err)\n\t}\n\n\tobj := parsed.ToObject(rt)\n\n\tmustDelete := func(prop string) {\n\t\tdelErr := obj.Delete(prop)\n\t\tif err != nil {\n\t\t\tcommon.Throw(rt, delErr)\n\t\t}\n\t}","sourceCodeStart":281,"sourceCodeEnd":317,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/execution/execution.go#L281-L317","documentation":"Error \"failed to encode the lib.Options as json: %w\" thrown in grafana/k6.","triggerScenarios":"Thrown at internal/js/modules/k6/execution/execution.go:299 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}