grafana/k6 · error

unable to serialise request object

Error message

unable to serialise request object: %w

What it means

Raised in buildInvokeRequest when MarshalJSON fails on the normalized request object — the payload contains values sobek cannot serialize to JSON (functions, unserializable native objects, cyclic structures).

Solutions

  1. Keep the request payload to plain JSON-serializable values
  2. Remove functions, Symbols, or cyclic references from the request
  3. Convert binary fields to the appropriate representation before invoking
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at internal/js/modules/k6/grpc/client.go:393 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of grafana/k6@8d06114777 (2026-08-18). Data as JSON: /api/errors/045175513824231b. Report an issue: GitHub.

Appendix: source

Thrown at internal/js/modules/k6/grpc/client.go:424

	if p.Timeout == time.Duration(0) {
		p.Timeout = 2 * time.Minute
	}

	if req == nil {
		return grpcReq, errors.New("request cannot be nil")
	}

	object := req.ToObject(c.vu.Runtime())

	var stack []*sobek.Object
	normalized, err := normalizeNumberStrings(object, c.vu.Runtime(), stack)
	if err != nil {
		return grpcReq, fmt.Errorf("unable to normalize number strings: %w", err)
	}

	b, err := normalized.ToObject(c.vu.Runtime()).MarshalJSON()
	if err != nil {
		return grpcReq, fmt.Errorf("unable to serialise request object: %w", err)
	}

	p.SetSystemTags(state, c.addr, method)

	return grpcext.InvokeRequest{
		Method:                 method,
		MethodDescriptor:       methodDesc,
		Timeout:                p.Timeout,
		DiscardResponseMessage: p.DiscardResponseMessage,
		Message:                b,
		TagsAndMeta:            &p.TagsAndMeta,
		Metadata:               p.Metadata,
	}, nil
}

// normalizeNumberStrings recursively traverses a sobek.Value. It creates a deep copy of any
// objects or arrays, and converts special float values (NaN, Infinity) to their
// string representations for proper JSON serialization.

View on GitHub (pinned to 8d06114777)