{"record":{"id":"92f38b2e9c20d48f","repo":"hyperledger/fabric","slug":"err-92f38b","errorCode":null,"errorMessage":"err","messagePattern":"err","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"protoutil/commonutils.go","lineNumber":28,"sourceCode":"\t\"crypto/rand\"\n\t\"fmt\"\n\n\tcb \"github.com/hyperledger/fabric-protos-go-apiv2/common\"\n\t\"github.com/hyperledger/fabric/internal/pkg/identity\"\n\t\"github.com/pkg/errors\"\n\t\"google.golang.org/protobuf/proto\"\n\t\"google.golang.org/protobuf/types/known/timestamppb\"\n)\n\n// MarshalOrPanic serializes a protobuf message and panics if this\n// operation fails\nfunc MarshalOrPanic(pb proto.Message) []byte {\n\tif !pb.ProtoReflect().IsValid() {\n\t\tpanic(errors.New(\"proto: Marshal called with nil\"))\n\t}\n\tdata, err := proto.Marshal(pb)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\treturn data\n}\n\n// Marshal serializes a protobuf message.\nfunc Marshal(pb proto.Message) ([]byte, error) {\n\tif !pb.ProtoReflect().IsValid() {\n\t\treturn nil, errors.New(\"proto: Marshal called with nil\")\n\t}\n\treturn proto.Marshal(pb)\n}\n\n// CreateNonceOrPanic generates a nonce using the common/crypto package\n// and panics if this operation fails.\nfunc CreateNonceOrPanic() []byte {\n\tnonce, err := CreateNonce()\n\tif err != nil {\n\t\tpanic(err)","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/protoutil/commonutils.go#L10-L46","documentation":"MarshalOrPanic panics with the raw error when proto.Marshal fails after the nil check. Since valid messages rarely fail to marshal, this panic indicates a genuine serialization problem (unsupported field, internal protobuf error). The panic value is the error itself, so the message string equals the underlying proto.Marshal error ('err').","triggerScenarios":"Calling MarshalOrPanic on a message whose proto.Marshal returns an error — e.g. a message built with corrupt nested state, or an extension/unknown-field problem in the protobuf runtime.","commonSituations":"Block or config generation (doOutputBlock, doOutputChannelCreateTx) with malformed nested messages; version mismatch between generated .pb.go code and the protobuf runtime; memory corruption in long-running processes.","solutions":["Inspect the panic value's message to find which message/field failed to marshal.","Regenerate .pb.go files with protoc-gen-go matching your google.golang.org/protobuf version.","Rebuild the offending message from scratch rather than mutating a partially built one.","Replace MarshalOrPanic with protoutil.Marshal where a graceful error path is preferable."],"exampleFix":"// before\nraw := protoutil.MarshalOrPanic(msg)\n// after\nraw, err := protoutil.Marshal(msg)\nif err != nil {\n\treturn fmt.Errorf(\"marshal failed: %w\", err)\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"func marshalSafe(pb proto.Message) (data []byte, err error) {\n\tdefer func() {\n\t\tif r := recover(); r != nil {\n\t\t\terr = fmt.Errorf(\"MarshalOrPanic failed: %v\", r)\n\t\t}\n\t}()\n\tdata = protoutil.MarshalOrPanic(pb)\n\treturn\n}","preventionTips":["Recover around MarshalOrPanic at boundaries between panic-based and error-based code.","Regenerate .pb.go files when upgrading the protobuf runtime.","Build messages from scratch rather than mutating partially constructed ones.","Use protoutil.Marshal where a graceful error return is possible."],"tags":["hyperledger-fabric","protobuf","panic","serialization"],"backgroundTag":"protobuf-marshal-failed","analyzedSha":"2736b63f8fd5932511d56fe68b7039d15977f7f6","analyzedAt":"2026-09-04T08:52:36.465Z","contentChangedAt":"2026-09-04T08:52:36.465Z","schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}