grafana/k6 · error
failed to encode the lib.Options as json: %w
Error message
failed to encode the lib.Options as json: %w
What it means
Error "failed to encode the lib.Options as json: %w" thrown in grafana/k6.
Source
Thrown at internal/js/modules/k6/execution/execution.go:299
for p, get := range props {
err := o.DefineAccessorProperty(p, rt.ToValue(get), nil, sobek.FLAG_FALSE, sobek.FLAG_TRUE)
if err != nil {
return nil, err
}
}
return o, nil
}
// optionsAsObject maps the lib.Options struct that contains the consolidated
// and derived options configuration in a sobek.Object.
//
// When values are not set then the default value returned from JSON is used.
// Most of the lib.Options are Nullable types so they will be null on default.
func optionsAsObject(rt *sobek.Runtime, options lib.Options) (*sobek.Object, error) {
b, err := json.Marshal(options)
if err != nil {
return nil, fmt.Errorf("failed to encode the lib.Options as json: %w", err)
}
// Using the native JS parser function guarantees getting
// the supported types for deep freezing the complex object.
jsonParse, _ := sobek.AssertFunction(rt.GlobalObject().Get("JSON").ToObject(rt).Get("parse"))
parsed, err := jsonParse(sobek.Undefined(), rt.ToValue(string(b)))
if err != nil {
common.Throw(rt, err)
}
obj := parsed.ToObject(rt)
mustDelete := func(prop string) {
delErr := obj.Delete(prop)
if err != nil {
common.Throw(rt, delErr)
}
}View on GitHub (pinned to 93accf6570)
When it happens
Trigger: Thrown at internal/js/modules/k6/execution/execution.go:299 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/61b3116a0cd59c78.
Report an issue: GitHub.