{"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/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/js/modules/k6/execution/execution.go#L281-L317","documentation":"Raised in optionsAsObject when json.Marshal fails to serialize the consolidated lib.Options struct so it can be mapped into a JS object for execution.scenario.options / test.options. The '%w' carries the marshal error. Since lib.Options is a plain serializable struct, failure indicates an internal inconsistency in derived option values — effectively an internal error rather than a user-script input problem at this call site.","triggerScenarios":"Thrown at internal/js/modules/k6/execution/execution.go:299 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Report as a k6 bug, including the options configuration that triggered it","Simplify/reduce options to isolate which setting produces an unmarshalable value","Upgrade k6 — internal marshalling of options has been hardened over versions"],"exampleFix":null,"handlingStrategy":"fallback","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"}