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
- Use an official, unmodified configtxlator binary matching your Fabric version.
- Verify the input decodes correctly by first running `configtxlator proto_decode` on a known-good .pb to produce valid JSON.
- 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
- Use official configtxlator binaries; this guard is effectively unreachable in standard builds.
- Rebuild cleanly from matching Fabric source tags if you maintain a custom binary.
- Treat occurrences as a tooling bug, not an input problem.
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
- error encode input
- message of type %s unknown
- error marshaling
- malformed org definition for org: %s
- error decoding input
AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04).
Data as JSON: /api/errors/01e900fdba955495.
Report an issue: GitHub.