grafana/k6 · error
parsing options from script got error while parsing
Error message
parsing options from script got error while parsing %q: %w
What it means
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).
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
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at internal/js/bundle.go:252 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of grafana/k6@3fcf5388d7 (2026-08-18).
Data as JSON: /api/errors/cd52fe2f15332ae9.
Report an issue: GitHub.
Appendix: source
Thrown at internal/js/bundle.go:252
return err
}
if len(b.callableExports) == 0 {
return errors.New("no exported functions in script")
}
return nil
}
func beautifyOptionsJSONUnmarshalError(data []byte, err error) error {
unmarshalTypError := new(json.UnmarshalTypeError)
if errors.As(err, &unmarshalTypError) {
e := unmarshalTypError
previousNewLineIndex := max(bytes.LastIndexByte(data[:e.Offset], '\n'), 0)
nextNewLineIndex := max(min(bytes.IndexByte(data[e.Offset:], '\n'), len(data)-1), int(e.Offset))
info := strings.TrimSpace(string(data[previousNewLineIndex:nextNewLineIndex]))
err = fmt.Errorf("parsing options from script got error while parsing %q: %w", info, e)
}
return err
}
// Instantiate creates a new runtime from this bundle.
func (b *Bundle) Instantiate(ctx context.Context, vuID uint64) (*BundleInstance, error) {
// Instantiate the bundle into a new VM using a bound init context. This uses a context with a
// runtime, but no state, to allow module-provided types to function within the init context.
vuImpl := &moduleVUImpl{
ctx: ctx,
runtime: sobek.New(),
events: events{
global: b.preInitState.Events,
local: event.NewEventSystem(100, b.preInitState.Logger),
},
}
if b.preInitState.FeatureFlags != nil && b.preInitState.FeatureFlags.AsyncMetricContext {
vuImpl.runtime.SetAsyncContextTracker(common.NewMetricContextTracker(vuImpl.State))View on GitHub (pinned to 3fcf5388d7)