grpc-ecosystem/grpc-gateway · error

no body field found

Error message

no body field found

What it means

Template-time error from binding.GetBodyFieldStructName: the binding has no body (Body nil or empty FieldPath), so there is no camel-cased struct field name to return. The generator template called it for a binding that does not carry a request body (e.g. a GET-style binding); '*' is the placeholder used by GetBodyFieldPath instead.

Source

Thrown at protoc-gen-grpc-gateway/internal/gengateway/template.go:48

	Registry          *descriptor.Registry
	AllowPatchFeature bool
	UseOpaqueAPI      bool
}

// GetBodyFieldPath returns the binding body's field path.
func (b binding) GetBodyFieldPath() string {
	if b.Body != nil && len(b.Body.FieldPath) != 0 {
		return b.Body.FieldPath.String()
	}
	return "*"
}

// GetBodyFieldStructName returns the binding body's struct field name.
func (b binding) GetBodyFieldStructName() (string, error) {
	if b.Body != nil && len(b.Body.FieldPath) != 0 {
		return casing.Camel(b.Body.FieldPath.String()), nil
	}
	return "", errors.New("no body field found")
}

// GetBodyFieldType returns the Go type of the body field.
func (b binding) GetBodyFieldType() (string, error) {
	if b.Body == nil || len(b.Body.FieldPath) == 0 {
		return "", errors.New("no body field found")
	}

	lastComponent := b.Body.FieldPath[len(b.Body.FieldPath)-1]
	fieldType := lastComponent.Target.GetType()

	// Handle message types
	if fieldType == descriptorpb.FieldDescriptorProto_TYPE_MESSAGE {
		// Get the parent message to provide proper lookup context
		parentMsg := lastComponent.Target.Message
		msg, err := b.Registry.LookupMsg(parentMsg.FQMN(), lastComponent.Target.GetTypeName())
		if err != nil {
			return "", fmt.Errorf("failed to lookup message type %s: %w", lastComponent.Target.GetTypeName(), err)

View on GitHub (pinned to a58a4436a3)

Solutions

  1. Only call GetBodyFieldStructName when the binding has Body != nil with a non-empty FieldPath.
  2. Use GetBodyFieldPath() which falls back to "*" for body-less bindings.
  3. Add a body: "..." clause to the HttpRule if a body was intended.
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at protoc-gen-grpc-gateway/internal/gengateway/template.go:48 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of grpc-ecosystem/grpc-gateway@a58a4436a3 (2026-09-02). Data as JSON: /api/errors/2deb9e46e65cbbd9. Report an issue: GitHub.