hyperledger/fabric · warning

error marshaling: proto: Marshal called with nil

Error message

error marshaling: proto: Marshal called with nil

What it means

In `encodeProto` (cmd/configtxlator/main.go:147), after successful JSON decoding, `msg` was still nil, so calling `proto.Marshal` would fail with 'proto: Marshal called with nil'. This is a defensive guard inside configtxlator; in practice it is nearly unreachable because DeepUnmarshalJSON would already have failed on a nil message.

Source

Thrown at cmd/configtxlator/main.go:147

	mt, err := protoregistry.GlobalTypes.FindMessageByName(protoreflect.FullName(msgName))
	if err != nil {
		return errors.Wrapf(err, "error encode input")
	}

	msgType := reflect.TypeOf(mt.Zero().Interface())

	if msgType == nil {
		return errors.Errorf("message of type %s unknown", msgType)
	}
	msg := reflect.New(msgType.Elem()).Interface().(proto.Message)

	err = protolator.DeepUnmarshalJSON(input, msg)
	if err != nil {
		return errors.Wrapf(err, "error decoding input")
	}

	if msg == nil {
		return errors.New("error marshaling: proto: Marshal called with nil")
	}
	out, err := proto.Marshal(msg)
	if err != nil {
		return errors.Wrapf(err, "error marshaling")
	}

	_, err = output.Write(out)
	if err != nil {
		return errors.Wrapf(err, "error writing output")
	}

	return nil
}

func decodeProto(msgName string, input, output *os.File) error {
	mt, err := protoregistry.GlobalTypes.FindMessageByName(protoreflect.FullName(msgName))
	if err != nil {
		return errors.Wrapf(err, "error encode input")

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Use an official, unmodified configtxlator binary matching your Fabric version.
  2. Verify the input decodes correctly by first running `configtxlator proto_decode` on a known-good .pb to produce valid JSON.
  3. If building from source, ensure reflect.New(msgType.Elem()) produces a non-nil proto.Message.
Defensive patterns

Strategy: try-catch

Try / catch

out, err := exec.Command("configtxlator", "proto_encode", ...).CombinedOutput()
if err != nil && strings.Contains(string(out), "Marshal called with nil") {
	log.Printf("configtxlator binary defect suspected; rebuild from official release: %s", out)
}

Prevention

When it happens

Trigger: Theoretically triggered when the decoded message ends up nil after DeepUnmarshalJSON succeeds — e.g. a degenerate/custom build where the reflect-constructed message is nil. Standard usage of `configtxlator proto_encode` does not hit this.

Common situations: Custom or patched configtxlator builds; pathological input where a nil message is constructed; version drift in protolator/proto helpers.

Related errors


AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04). Data as JSON: /api/errors/01e900fdba955495. Report an issue: GitHub.