{"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":"validation","errorClass":null,"httpStatus":null,"severity":"critical","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\tvuImpl.eventLoop = eventloop.New(vuImpl)\n\tbi, err := b.instantiate(vuImpl, vuID)","sourceCodeStart":234,"sourceCodeEnd":270,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/bundle.go#L234-L270","documentation":"When exported options decode into lib.Options with a value of the wrong JSON type (json.UnmarshalTypeError), beautifyOptionsJSONUnmarshalError re-runs the parse, extracts the offending line from the pretty-printed options JSON, and shows it in quotes with the underlying type error. The run aborts with AbortedByScriptError / exit code 104 (InvalidConfig).","triggerScenarios":"A recognized option key holding the wrong value type: duration: 30 (must be the string '30s'), vus: '10' (must be a number), iterations: true, thresholds: 'p(95)<200' (must be an object), hosts given as an array instead of an object of host overrides.","commonSituations":"Options assembled from templates or environment variables where everything becomes a string; porting YAML/JSON config into a JS export; durations written as bare numbers by mistake.","solutions":["Look at the quoted fragment in the message - it is the exact line of the marshaled options that failed; fix that value's type","Use quoted strings with units for every duration (duration, gracefulStop, gracefulRampDown) and plain numbers for vus/iterations/rate","Keep thresholds, hosts, and executor options as objects/arrays, never strings","Pre-flight check in CI: `k6 inspect script.js` parses options without generating load"],"exampleFix":"// before: duration as number -> type error\nexport const options = { vus: 2, duration: 30 };\n\n// after: duration as a unit string\nexport const options = { vus: 2, duration: '30s' };","handlingStrategy":"validation","validationCode":"# CI pre-flight: k6 inspect parses exported options and exits non-zero on type errors\nk6 inspect script.js > /dev/null || exit 1","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Write all durations as unit strings ('30s', '1m') and all counts as numbers","When options are built from environment variables, coerce explicitly (Number(), String()) before composing","Run k6 inspect locally before every commit that touches options"],"tags":["options","type-mismatch","json","configuration"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}