{"record":{"id":"5917af5f223ae579","repo":"hyperledger/fabric","slug":"error-marshaling-transaction-proto-marshal-calle","errorCode":null,"errorMessage":"error marshaling Transaction: proto: Marshal called with nil","messagePattern":"error marshaling Transaction: proto: Marshal called with nil","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"protoutil/proputils.go","lineNumber":201,"sourceCode":"\t\treturn nil, errors.New(\"error marshaling Header: proto: Marshal called with nil\")\n\t}\n\tbytes, err := proto.Marshal(hdr)\n\treturn bytes, errors.Wrap(err, \"error marshaling Header\")\n}\n\n// GetBytesSignatureHeader get the bytes of SignatureHeader from the message\nfunc GetBytesSignatureHeader(hdr *common.SignatureHeader) ([]byte, error) {\n\tif hdr == nil {\n\t\treturn nil, errors.New(\"error marshaling SignatureHeader: proto: Marshal called with nil\")\n\t}\n\tbytes, err := proto.Marshal(hdr)\n\treturn bytes, errors.Wrap(err, \"error marshaling SignatureHeader\")\n}\n\n// GetBytesTransaction get the bytes of Transaction from the message\nfunc GetBytesTransaction(tx *peer.Transaction) ([]byte, error) {\n\tif tx == nil {\n\t\treturn nil, errors.New(\"error marshaling Transaction: proto: Marshal called with nil\")\n\t}\n\tbytes, err := proto.Marshal(tx)\n\treturn bytes, errors.Wrap(err, \"error unmarshalling Transaction\")\n}\n\n// GetBytesPayload get the bytes of Payload from the message\nfunc GetBytesPayload(payl *common.Payload) ([]byte, error) {\n\tif payl == nil {\n\t\treturn nil, errors.New(\"error marshaling Payload: proto: Marshal called with nil\")\n\t}\n\tbytes, err := proto.Marshal(payl)\n\treturn bytes, errors.Wrap(err, \"error marshaling Payload\")\n}\n\n// GetBytesEnvelope get the bytes of Envelope from the message\nfunc GetBytesEnvelope(env *common.Envelope) ([]byte, error) {\n\tif env == nil {\n\t\treturn nil, errors.New(\"error marshaling Envelope: proto: Marshal called with nil\")","sourceCodeStart":183,"sourceCodeEnd":219,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/protoutil/proputils.go#L183-L219","documentation":"GetBytesTransaction returns 'error marshaling Transaction: proto: Marshal called with nil' when the *peer.Transaction passed to it is nil. proto.Marshal cannot serialize a nil message, so the helper pre-checks and returns this descriptive error instead.","triggerScenarios":"Calling protoutil.GetBytesTransaction(nil) directly, or callers createSignedTxTwoActions, prepareTransaction, CreateSignedTx receiving a nil Transaction because payload assembly (e.g. GetPayloads returning nil respPayload) failed upstream.","commonSituations":"Building signed transactions in SDK/test code where the ChaincodeAction/ProposalResponse failed validation and a nil Transaction was silently propagated to serialization.","solutions":["Verify the Transaction is non-nil before calling GetBytesTransaction","Check upstream GetPayloads results: ensure endorsements produced valid ProposalResponse payloads so the Transaction is built","Add a nil check on tx in createSignedTx/prepareTransaction before serialization"],"exampleFix":"// before\ntxBytes, err := protoutil.GetBytesTransaction(tx) // tx may be nil\n// after\nif tx == nil {\n\treturn nil, errors.New(\"transaction is nil; check endorsement responses\")\n}\ntxBytes, err := protoutil.GetBytesTransaction(tx)","handlingStrategy":"validation","validationCode":"func validTx(tx *peer.Transaction) error {\n\tif tx == nil {\n\t\treturn errors.New(\"Transaction is nil\")\n\t}\n\tif len(tx.Actions) == 0 {\n\t\treturn errors.New(\"Transaction has no actions\")\n\t}\n\treturn nil\n}","typeGuard":"func hasTransaction(tx *peer.Transaction) bool {\n\treturn tx != nil\n}","tryCatchPattern":"txBytes, err := protoutil.GetBytesTransaction(tx)\nif err != nil {\n\treturn nil, fmt.Errorf(\"cannot serialize transaction: %w\", err)\n}","preventionTips":["Check every ProposalResponse for success before merging into a Transaction","Ensure GetPayloads errors are handled, not ignored","Add table tests covering nil and empty transaction inputs"],"tags":["hyperledger-fabric","protobuf","nil-pointer","transaction"],"backgroundTag":"proto-marshal-nil-message","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"}