grafana/k6 · error

failed to unmarshal the message: %w

Error message

failed to unmarshal the message: %w

What it means

The JSON produced by marshaling a dynamic protobuf message could not be unmarshaled into a generic Go value. This is the second half of the convert round-trip; failing here indicates a mismatch between what protojson emitted and what encoding/json accepts (e.g. precision or number-format edge cases), and is essentially an internal/k6-side anomaly rather than a user input error.

Source

Thrown at internal/lib/netext/grpcext/stream.go:105

// and a value like this:
// msg := Point{X: 6, Y: 4, Z: 0}
// would result in JSON output:
// {"x":6,"y":4}
// rather than the desired:
// {"x":6,"y":4,"z":0}
func convert(marshaler protojson.MarshalOptions, msg *dynamicpb.Message) (any, error) {
	// TODO(olegbespalov): add the test that checks that message is not nil

	raw, err := marshaler.Marshal(msg)
	if err != nil {
		return nil, fmt.Errorf("failed to marshal the message: %w", err)
	}

	var back any

	err = json.Unmarshal(raw, &back)
	if err != nil {
		return nil, fmt.Errorf("failed to unmarshal the message: %w", err)
	}

	return back, err
}

// CloseSend closes the stream
func (s *Stream) CloseSend() error {
	return s.raw.CloseSend()
}

// BuildMessage builds a message from the input
func (s *Stream) buildMessage(b []byte) (*dynamicpb.Message, error) {
	msg := dynamicpb.NewMessage(s.methodDescriptor.Input())
	if err := s.unmarshaler.Unmarshal(b, msg); err != nil {
		return nil, fmt.Errorf("can't serialise request object to protocol buffer: %w", err)
	}

	return msg, nil

View on GitHub (pinned to 01ffac6f24)

Solutions

  1. Upgrade k6 to the latest version where conversion edge cases may be fixed
  2. Report the failing message type and payload to the k6 issue tracker
  3. As a workaround, handle the message's raw response on the server side instead of relying on the converted object
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at internal/lib/netext/grpcext/stream.go:105 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/9ab710a1648abb2a. Report an issue: GitHub.