{"record":{"id":"7eee9177e974e049","repo":"hyperledger/fabric","slug":"error-marshaling-chaincodeevent","errorCode":null,"errorMessage":"error marshaling ChaincodeEvent","messagePattern":"error marshaling ChaincodeEvent","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"protoutil/proputils.go","lineNumber":158,"sourceCode":"\treturn cppBytes, errors.Wrap(err, \"error marshaling ChaincodeProposalPayload\")\n}\n\n// GetBytesResponse gets the bytes of Response\nfunc GetBytesResponse(res *peer.Response) ([]byte, error) {\n\tif res == nil {\n\t\treturn nil, errors.New(\"error marshaling Response: proto: Marshal called with nil\")\n\t}\n\tresBytes, err := proto.Marshal(res)\n\treturn resBytes, errors.Wrap(err, \"error marshaling Response\")\n}\n\n// GetBytesChaincodeEvent gets the bytes of ChaincodeEvent\nfunc GetBytesChaincodeEvent(event *peer.ChaincodeEvent) ([]byte, error) {\n\tif event == nil {\n\t\treturn nil, errors.New(\"error marshaling ChaincodeEvent: proto: Marshal called with nil\")\n\t}\n\teventBytes, err := proto.Marshal(event)\n\treturn eventBytes, errors.Wrap(err, \"error marshaling ChaincodeEvent\")\n}\n\n// GetBytesChaincodeActionPayload get the bytes of ChaincodeActionPayload from\n// the message\nfunc GetBytesChaincodeActionPayload(cap *peer.ChaincodeActionPayload) ([]byte, error) {\n\tif cap == nil {\n\t\treturn nil, errors.New(\"error marshaling ChaincodeActionPayload: proto: Marshal called with nil\")\n\t}\n\tcapBytes, err := proto.Marshal(cap)\n\treturn capBytes, errors.Wrap(err, \"error marshaling ChaincodeActionPayload\")\n}\n\n// GetBytesProposalResponse gets proposal bytes response\nfunc GetBytesProposalResponse(pr *peer.ProposalResponse) ([]byte, error) {\n\tif pr == nil {\n\t\treturn nil, errors.New(\"error marshaling ProposalResponse: proto: Marshal called with nil\")\n\t}\n\trespBytes, err := proto.Marshal(pr)","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/protoutil/proputils.go#L140-L176","documentation":"This is the wrapped error from proto.Marshal inside GetBytesChaincodeEvent for a non-nil *peer.ChaincodeEvent whose serialization failed. errors.Wrap adds the 'error marshaling ChaincodeEvent' context on top of the underlying proto error.","triggerScenarios":"proto.Marshal failing on a non-nil ChaincodeEvent — rare with well-formed generated messages; usually indicates a version mismatch between the generated peer protobuf code and the proto runtime, or a corrupted message built from bad bytes.","commonSituations":"Mixed Fabric module versions in one binary (e.g. fabric-protos-go upgraded inconsistently), reflection/codegen issues, or events reconstructed by manually decoding raw bytes.","solutions":["Inspect the underlying cause via errors.Cause(err) for the true proto failure.","Run go mod tidy / consistent upgrade of github.com/hyperledger/fabric-protos-go and the proto runtime across all modules.","Re-derive the event from the block/transaction data instead of reusing a hand-built struct.","If the event was actually nil, add the nil guard (see the 'Marshal called with nil' variant)."],"exampleFix":"// before\nevBytes, err := protoutil.GetBytesChaincodeEvent(evt)\nif err != nil {\n    return fmt.Errorf(\"event failed: %s\", err)\n}\n// after\nevBytes, err := protoutil.GetBytesChaincodeEvent(evt)\nif err != nil {\n    return errors.Wrap(errors.Cause(err), \"event serialization failed\")\n}","handlingStrategy":"try-catch","validationCode":"if evt == nil {\n    return nil, errors.New(\"ChaincodeEvent is nil\")\n}","typeGuard":"func isSerializableEvent(evt *peer.ChaincodeEvent) bool {\n    return evt != nil\n}","tryCatchPattern":"evBytes, err := protoutil.GetBytesChaincodeEvent(evt)\nif err != nil {\n    return errors.Wrap(errors.Cause(err), \"ChaincodeEvent serialization failed\")\n}","preventionTips":["Surface errors.Cause(err) when logging serialization failures.","After any fabric-protos-go upgrade, run go mod tidy and rebuild all modules together.","Re-derive events from transaction data rather than reconstructing structs by hand."],"tags":["grpc","protobuf","serialization","hyperledger-fabric"],"backgroundTag":"proto-marshal-failed","analyzedSha":"2736b63f8fd5932511d56fe68b7039d15977f7f6","analyzedAt":"2026-09-04T08:52:36.465Z","contentChangedAt":"2026-09-04T08:52:36.465Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}