grafana/k6 · error
failed to marshal the message: %w
Error message
failed to marshal the message: %w
What it means
protojson failed to marshal a dynamic response message back to JSON during conversion. k6 converts dynamic protobuf messages to plain Go values via a JSON round-trip so JS property access works; this fires when the message contains data protojson refuses to serialize (e.g. google.protobuf.Any with an unresolvable type or invalid UTF-8 in a string field).
Source
Thrown at internal/lib/netext/grpcext/stream.go:98
//
// message Point {
// double x = 1;
// double y = 2;
// double z = 3;
// }
//
// 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 inputView on GitHub (pinned to 01ffac6f24)
Solutions
- Check that response string fields contain valid UTF-8 and Any fields reference resolvable types
- Ensure the client's type resolver knows all message types involved (use reflection from the live server or a complete proto bundle)
- Capture the actual response server-side and validate it against the schema
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at internal/lib/netext/grpcext/stream.go:98 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/139cd196c5eec0c6.
Report an issue: GitHub.