{"record":{"id":"e4848f8b5748431f","repo":"grafana/k6","slug":"error-parsing-script-options-w","errorCode":null,"errorMessage":"error parsing script options: %w","messagePattern":"error parsing script options: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/bundle.go","lineNumber":205,"sourceCode":"\tvar err error\n\tch := make(chan struct{})\n\tbi.mainModule.GetExportedNames(func(names []string) {\n\t\tdefer close(ch)\n\t\tfor _, k := range names {\n\t\t\tv := bi.getExported(k)\n\t\t\tif _, ok := sobek.AssertFunction(v); ok && k != consts.Options {\n\t\t\t\tb.callableExports[k] = struct{}{}\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tswitch k {\n\t\t\tcase consts.Options:\n\t\t\t\tif !updateOptions || v == nil {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tvar data []byte\n\t\t\t\tdata, err = json.MarshalIndent(v.Export(), \"\", \"  \")\n\t\t\t\tif err != nil {\n\t\t\t\t\terr = fmt.Errorf(\"error parsing script options: %w\", err)\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tdec := json.NewDecoder(bytes.NewReader(data))\n\t\t\t\tdec.DisallowUnknownFields()\n\t\t\t\tif err = dec.Decode(&b.Options); err != nil {\n\t\t\t\t\tif uerr := json.Unmarshal(data, &b.Options); uerr != nil {\n\t\t\t\t\t\t// Beautify the error so we can try to show the user the key and potential value that is failing to parse\n\t\t\t\t\t\tuerr = beautifyOptionsJSONUnmarshalError(data, uerr)\n\t\t\t\t\t\terr = errext.WithAbortReasonIfNone(\n\t\t\t\t\t\t\terrext.WithExitCodeIfNone(uerr, exitcodes.InvalidConfig),\n\t\t\t\t\t\t\terrext.AbortedByScriptError,\n\t\t\t\t\t\t)\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\t\t\t\t\tb.preInitState.Logger.WithError(err).Warn(\"There were unknown fields in the options exported in the script\")\n\t\t\t\t\terr = nil\n\t\t\t\t}\n\t\t\tcase consts.SetupFn:","sourceCodeStart":187,"sourceCodeEnd":223,"githubUrl":"https://github.com/grafana/k6/blob/3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee/internal/js/bundle.go#L187-L223","documentation":"populateExports wraps json.MarshalIndent failing on the script's exported options object (v.Export() of the 'options' export). Fires when the exported options contain values that cannot be converted to JSON (e.g. functions, cyclical references, or non-serializable JS objects).","triggerScenarios":"Thrown at internal/js/bundle.go:205 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Make the exported options a plain object of primitive/serializable values","Remove functions or complex objects from the options export","Ensure options only contains keys k6 understands (scenarios, thresholds, etc.)"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}