{"record":{"id":"4d5a1fb0026ddf20","repo":"hyperledger/fabric","slug":"error-marshaling-envelope-proto-marshal-called-w","errorCode":null,"errorMessage":"error marshaling Envelope: proto: Marshal called with nil","messagePattern":"error marshaling Envelope: proto: Marshal called with nil","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"protoutil/proputils.go","lineNumber":219,"sourceCode":"\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) {\n\tenv, err := GetEnvelopeFromBlock(envBytes)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\treturn GetActionFromEnvelopeMsg(env)\n}\n\nfunc GetActionFromEnvelopeMsg(env *common.Envelope) (*peer.ChaincodeAction, error) {\n\tpayl, err := UnmarshalPayload(env.Payload)","sourceCodeStart":201,"sourceCodeEnd":237,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/protoutil/proputils.go#L201-L237","documentation":"GetBytesEnvelope returns 'error marshaling Envelope: proto: Marshal called with nil' when the *common.Envelope argument is nil. An Envelope wraps the serialized Payload plus a signature; a nil Envelope cannot be marshaled by protobuf, so the helper returns this explicit error.","triggerScenarios":"Calling protoutil.GetBytesEnvelope(nil), or test/SDK callers (TestInvoke, TestValidateDeployOK, TestRWSetTooBig, etc.) passing an envelope that was never created because proposal signing or CreateSignedTx failed earlier.","commonSituations":"End-to-end chaincode invoke/deploy test scaffolding where envelope construction is skipped or fails (no signer configured, signing error ignored) and the nil envelope flows into serialization.","solutions":["Nil-check the Envelope before marshaling","Verify CreateSignedTx returned a non-nil, signed envelope and handle its error before calling GetBytesEnvelope","Ensure a valid signer (bccsp/crypto provider) is configured so the signing step completes"],"exampleFix":"// before\nenvBytes, err := protoutil.GetBytesEnvelope(env)\n// after\nif env == nil || env.Payload == nil {\n\treturn nil, errors.New(\"envelope or payload is nil\")\n}\nenvBytes, err := protoutil.GetBytesEnvelope(env)","handlingStrategy":"validation","validationCode":"func validEnvelope(env *common.Envelope) error {\n\tif env == nil {\n\t\treturn errors.New(\"Envelope is nil\")\n\t}\n\tif len(env.Payload) == 0 {\n\t\treturn errors.New(\"Envelope has empty payload\")\n\t}\n\treturn nil\n}","typeGuard":"func isSignedEnvelope(env *common.Envelope) bool {\n\treturn env != nil && len(env.Payload) > 0 && len(env.Signature) > 0\n}","tryCatchPattern":"envBytes, err := protoutil.GetBytesEnvelope(env)\nif err != nil {\n\treturn nil, fmt.Errorf(\"envelope serialization failed: %w\", err)\n}","preventionTips":["Ensure CreateSignedTx succeeded and returned a non-nil envelope before serializing","Configure a working signer so the signing step produces a signature","Handle CreateSignedTx errors before passing the envelope on"],"tags":["hyperledger-fabric","protobuf","nil-pointer","envelope"],"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"}