grafana/k6 · error

unmarshaling %q to lifecycle event: %w

Error message

unmarshaling %q to lifecycle event: %w

What it means

Error "unmarshaling %q to lifecycle event: %w" thrown in grafana/k6.

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 93accf6570)

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@93accf6570 (2026-08-15). Data as JSON: /api/errors/65aa56849eb7dcd4. Report an issue: GitHub.