go-kratos/kratos · error

http: stream body field %q is not a singular message field

Error message

http: stream body field %q is not a singular message field

What it means

Error "http: stream body field %q is not a singular message field" thrown in go-kratos/kratos.

Source

Thrown at transport/http/stream.go:248

	return nil
}

// recvMessage decodes the next frame. When a named body field is declared the frame
// carries only that field's payload, so it is decoded into a freshly allocated sub-message
// and assigned back onto m; otherwise the frame is decoded into m directly. The generator
// only declares a body field for a singular message-kind field, so a mismatch here is a
// programming error and is reported rather than silently ignored.
func (s *serverStream) recvMessage(m any) error {
	if s.bodyField == "" {
		return s.RecvMsg(m)
	}
	pm, ok := m.(proto.Message)
	if !ok {
		return fmt.Errorf("http: stream body field %q requires a proto.Message, got %T", s.bodyField, m)
	}
	fd := pm.ProtoReflect().Descriptor().Fields().ByName(protoreflect.Name(s.bodyField))
	if fd == nil || fd.Kind() != protoreflect.MessageKind || fd.IsList() || fd.IsMap() {
		return fmt.Errorf("http: stream body field %q is not a singular message field", s.bodyField)
	}
	sub := pm.ProtoReflect().NewField(fd)
	if err := s.RecvMsg(sub.Message().Interface()); err != nil {
		return err
	}
	pm.ProtoReflect().Set(fd, sub)
	return nil
}

func (s *serverStream) SendAndClose(m any) error {
	return s.SendMsg(m)
}

func (s *serverStream) SendMsg(m any) error {
	switch s.mode {
	case streamModeSSE:
		return s.sendSSE("message", m)
	case streamModeWebSocket:

View on GitHub (pinned to 668db92c2c)

When it happens

Trigger: Thrown at transport/http/stream.go:248 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of go-kratos/kratos@668db92c2c (2026-08-16). Data as JSON: /api/errors/b64ff92383d16aca. Report an issue: GitHub.