{"record":{"id":"cd52fe2f15332ae9","repo":"grafana/k6","slug":"parsing-options-from-script-got-error-while-parsin","errorCode":null,"errorMessage":"parsing options from script got error while parsing %q: %w","messagePattern":"parsing options from script got error while parsing %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/bundle.go","lineNumber":252,"sourceCode":"\t\treturn err\n\t}\n\n\tif len(b.callableExports) == 0 {\n\t\treturn errors.New(\"no exported functions in script\")\n\t}\n\n\treturn nil\n}\n\nfunc beautifyOptionsJSONUnmarshalError(data []byte, err error) error {\n\tunmarshalTypError := new(json.UnmarshalTypeError)\n\tif errors.As(err, &unmarshalTypError) {\n\t\te := unmarshalTypError\n\t\tpreviousNewLineIndex := max(bytes.LastIndexByte(data[:e.Offset], '\\n'), 0)\n\t\tnextNewLineIndex := max(min(bytes.IndexByte(data[e.Offset:], '\\n'), len(data)-1), int(e.Offset))\n\n\t\tinfo := strings.TrimSpace(string(data[previousNewLineIndex:nextNewLineIndex]))\n\t\terr = fmt.Errorf(\"parsing options from script got error while parsing %q: %w\", info, e)\n\t}\n\treturn err\n}\n\n// Instantiate creates a new runtime from this bundle.\nfunc (b *Bundle) Instantiate(ctx context.Context, vuID uint64) (*BundleInstance, error) {\n\t// Instantiate the bundle into a new VM using a bound init context. This uses a context with a\n\t// runtime, but no state, to allow module-provided types to function within the init context.\n\tvuImpl := &moduleVUImpl{\n\t\tctx:     ctx,\n\t\truntime: sobek.New(),\n\t\tevents: events{\n\t\t\tglobal: b.preInitState.Events,\n\t\t\tlocal:  event.NewEventSystem(100, b.preInitState.Logger),\n\t\t},\n\t}\n\tif b.preInitState.FeatureFlags != nil && b.preInitState.FeatureFlags.AsyncMetricContext {\n\t\tvuImpl.runtime.SetAsyncContextTracker(common.NewMetricContextTracker(vuImpl.State))","sourceCodeStart":234,"sourceCodeEnd":270,"githubUrl":"https://github.com/grafana/k6/blob/3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee/internal/js/bundle.go#L234-L270","documentation":"beautifyOptionsJSONUnmarshalError rewrites a json.UnmarshalTypeError raised while decoding the script's exported options into lib.Options. It extracts the offending line from the marshaled JSON so the user sees which option key has the wrong type (e.g. a string where a number/boolean/object is expected).","triggerScenarios":"Thrown at internal/js/bundle.go:252 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check the quoted line in the error to find the offending option key","Fix the value's type in the script's exported options to match k6's schema (e.g. numeric fields need numbers, not strings)","Consult the options documentation for the expected shape of each key"],"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"}