{"record":{"id":"6cb626c8a01e0f4b","repo":"hyperledger/fabric","slug":"error-marshaling-payload-proto-marshal-called-wi","errorCode":null,"errorMessage":"error marshaling Payload: proto: Marshal called with nil","messagePattern":"error marshaling Payload: proto: Marshal called with nil","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"protoutil/proputils.go","lineNumber":210,"sourceCode":"\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\")\n\t}\n\tbytes, err := proto.Marshal(env)\n\treturn bytes, errors.Wrap(err, \"error marshaling Envelope\")\n}\n\n// GetActionFromEnvelope extracts a ChaincodeAction message from a\n// serialized Envelope\n// TODO: fix function name as per FAB-11831\nfunc GetActionFromEnvelope(envBytes []byte) (*peer.ChaincodeAction, error) {","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/protoutil/proputils.go#L192-L228","documentation":"GetBytesPayload returns 'error marshaling Payload: proto: Marshal called with nil' when the *common.Payload argument is nil. The helper pre-checks nil because proto.Marshal errors out on nil messages. Payload is the core envelope body, so this blocks proposal/envelope creation.","triggerScenarios":"Calling protoutil.GetBytesPayload(nil), or callers createSignedCCDepSpec, createSignedTxTwoActions, prepareTransaction, CreateSignedTx, TestPreprocessProtoBlock passing a payload that failed to construct (e.g. MarshalPayloadOrPanic skipped, header/chaincode data unset).","commonSituations":"Chaincode install/deploy/upgrade proposal builders where the ChaincodeDeploymentSpec marshaling failed, or tests constructing payloads manually and forgetting to populate fields.","solutions":["Nil-check the Payload before serialization","Confirm the payload was built with protoutil.CreatePayload / MarshalPayloadOrPanic and its Header and Data are populated","In CDS flows, verify the ChaincodeDeploymentSpec marshaled successfully before embedding it in the payload"],"exampleFix":"// before\npaylBytes, err := protoutil.GetBytesPayload(payl)\n// after\nif payl == nil || payl.Header == nil {\n\treturn nil, errors.New(\"payload or its header is nil\")\n}\npaylBytes, err := protoutil.GetBytesPayload(payl)","handlingStrategy":"validation","validationCode":"func validPayload(p *common.Payload) error {\n\tif p == nil {\n\t\treturn errors.New(\"Payload is nil\")\n\t}\n\tif p.Header == nil || p.Header.ChannelHeader == nil {\n\t\treturn errors.New(\"Payload missing header\")\n\t}\n\treturn nil\n}","typeGuard":"func hasPayload(env *common.Envelope) bool {\n\treturn env != nil && env.Payload != nil\n}","tryCatchPattern":"paylBytes, err := protoutil.GetBytesPayload(payl)\nif err != nil {\n\treturn nil, fmt.Errorf(\"payload serialization failed: %w\", err)\n}","preventionTips":["Construct payloads with protoutil.CreatePayload and populate Header and Data","Verify CDS marshaled successfully before embedding in a payload","Add nil-payload unit tests to proposal builders"],"tags":["hyperledger-fabric","protobuf","nil-pointer","payload"],"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"}