grafana/k6 · error
unmarshaling to lifecycle event
Error message
unmarshaling %q to lifecycle event: %w
What it means
Returned by LifecycleEvent.UnmarshalJSON when the raw JSON bytes cannot be unmarshaled into a string — typically a non-quoted value such as a number or object where a quoted lifecycle event name (e.g. "load") was expected. The input at fault is the JSON value being decoded.
Solutions
- Pass the lifecycle event as a quoted JSON string, e.g. \"load\" or \"domcontentloaded\"
- Validate script options before running: the value must be one of load, domcontentloaded, networkidle
- Inspect the JSON payload producing the decode error and correct its type
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at internal/js/modules/k6/browser/common/lifecycle.go:63 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18).
Data as JSON: /api/errors/65aa56849eb7dcd4.
Report an issue: GitHub.
Appendix: source
Thrown at internal/js/modules/k6/browser/common/lifecycle.go:63
"load": LifecycleEventLoad,
"domcontentloaded": LifecycleEventDOMContentLoad,
"networkidle": LifecycleEventNetworkIdle,
}
// MarshalJSON marshals the enum as a quoted JSON string.
func (l LifecycleEvent) MarshalJSON() ([]byte, error) {
buffer := bytes.NewBufferString(`"`)
buffer.WriteString(lifecycleEventToString[l])
buffer.WriteString(`"`)
return buffer.Bytes(), nil
}
// UnmarshalJSON unmarshals a quoted JSON string to the enum value.
func (l *LifecycleEvent) UnmarshalJSON(b []byte) error {
var j string
err := json.Unmarshal(b, &j)
if err != nil {
return fmt.Errorf("unmarshaling %q to lifecycle event: %w", b, err)
}
// Note that if the string cannot be found then it will be set to the zero value.
*l = lifecycleEventToID[j]
return nil
}
// MarshalText returns the string representation of the enum value.
// It returns an error if the enum value is invalid.
func (l *LifecycleEvent) MarshalText() ([]byte, error) {
if l == nil {
return []byte(""), nil
}
var (
ok bool
s string
)
if s, ok = lifecycleEventToString[*l]; !ok {
return nil, fmt.Errorf("invalid lifecycle event: %v", int(*l))View on GitHub (pinned to 01ffac6f24)