{"record":{"id":"dc8c6a17a8d74189","repo":"hyperledger/fabric","slug":"failed-to-marshal-request-envelope-proto-marshal","errorCode":null,"errorMessage":"failed to marshal request envelope: proto: Marshal called with nil","messagePattern":"failed to marshal request envelope: proto: Marshal called with nil","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"orderer/consensus/smartbft/chain.go","lineNumber":314,"sourceCode":"\t\tgo func(w *worker) {\n\t\t\tdefer wg.Done()\n\t\t\tw.doWork()\n\t\t}(workers[i])\n\t}\n\n\twg.Wait()\n}\n\nfunc (c *BFTChain) pruneBadRequests() {\n\tc.consensus.Pool.Prune(func(req []byte) error {\n\t\t_, err := c.consensus.Verifier.VerifyRequest(req)\n\t\treturn err\n\t})\n}\n\nfunc (c *BFTChain) submit(env *cb.Envelope) error {\n\tif env == nil {\n\t\treturn errors.New(\"failed to marshal request envelope: proto: Marshal called with nil\")\n\t}\n\treqBytes, err := proto.Marshal(env)\n\tif err != nil {\n\t\treturn errors.Wrapf(err, \"failed to marshal request envelope\")\n\t}\n\n\tc.Logger.Debugf(\"Consensus.SubmitRequest, node id %d\", c.Config.SelfID)\n\tif err = c.consensus.SubmitRequest(reqBytes); err != nil {\n\t\treturn errors.Wrapf(err, \"failed to submit request\")\n\t}\n\treturn nil\n}\n\n// Order accepts a message which has been processed at a given configSeq.\n// If the configSeq advances, it is the responsibility of the consenter\n// to revalidate and potentially discard the message\n// The consenter may return an error, indicating the message was not accepted\nfunc (c *BFTChain) Order(env *cb.Envelope, configSeq uint64) error {","sourceCodeStart":296,"sourceCodeEnd":332,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/orderer/consensus/smartbft/chain.go#L296-L332","documentation":"BFTChain.submit marshals the request envelope with proto.Marshal after a nil check; when env is nil the smartbft implementation returns the literal message \"failed to marshal request envelope: proto: Marshal called with nil\". It surfaces when Order or Configure propagate a nil envelope into the chain's submit path.","triggerScenarios":"Calling c.Order(nil) or c.Configure(nil) (or an upstream path that produced a nil *cb.Envelope) on a smartbft BFTChain.","commonSituations":"A filter/processor upstream returned nil envelope on error without short-circuiting; refactored code path that no longer guarantees a constructed envelope; misbehaving custom consensus/processor feeding nil into Order.","solutions":["Guard the call site: never pass a nil envelope to Order/Configure; return early when envelope construction fails","Check errors from upstream envelope creation (e.g. protoutil.Marshal/Filter results) before calling Order","Fix the producer that returned nil instead of a valid cb.Envelope or a proper error"],"exampleFix":"// before\nenv, err := buildEnvelope(msg)\n// err ignored, env may be nil\nc.Order(env)\n// after\nenv, err := buildEnvelope(msg)\nif err != nil {\n    return errors.Wrap(err, \"failed to build envelope\")\n}\nif env == nil {\n    return errors.New(\"nil envelope\")\n}\nc.Order(env)","handlingStrategy":"try-catch","validationCode":"if env == nil {\n    return errors.New(\"cannot submit nil envelope\")\n}","typeGuard":null,"tryCatchPattern":"defer func() {\n    if r := recover(); r != nil { /* handle nil envelope path */ }\n}()\nif env == nil {\n    return errors.New(\"failed to marshal request envelope: proto: Marshal called with nil\")\n}\nif err := chain.Order(env); err != nil {\n    return errors.Wrap(err, \"submit failed\")\n}","preventionTips":["Always check the error from envelope construction before calling Order/Configure","Return early on upstream errors instead of passing zero-value envelopes","Add unit tests asserting Order/Configure reject nil envelopes explicitly"],"tags":["hyperledger-fabric","smartbft","protobuf","nil-envelope"],"backgroundTag":"proto-marshal-nil","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"}