{"record":{"id":"848d3613f11780b1","repo":"hyperledger/fabric","slug":"failed-to-marshal-request-envelope","errorCode":null,"errorMessage":"failed to marshal request envelope","messagePattern":"failed to marshal request envelope","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"orderer/consensus/smartbft/chain.go","lineNumber":318,"sourceCode":"\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 {\n\tseq := c.support.Sequence()\n\tif configSeq < seq {\n\t\tc.Logger.Warnf(\"Normal message was validated against %d, although current config seq has advanced (%d)\", configSeq, seq)\n\t\tif _, err := c.support.ProcessNormalMsg(env); err != nil {","sourceCodeStart":300,"sourceCodeEnd":336,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/orderer/consensus/smartbft/chain.go#L300-L336","documentation":"This error is returned by BFTChain.submit when the incoming *cb.Envelope cannot be serialized with proto.Marshal, or (defensively) when the envelope itself is nil. The ordering node cannot hand a request to the SmartBFT consensus engine without its protobuf bytes, so submission is aborted. It wraps the underlying protobuf error via pkg/errors.Wrapf.","triggerScenarios":"Calling Order() or Configure() with a nil *cb.Envelope (the submit function explicitly rejects nil), or passing an envelope containing a message that fails proto.Marshal (e.g. an embedded message with an invalid field, corrupted bytes, or a struct that exceeds protobuf limits).","commonSituations":"A client (Broadcast stream or SendTx path) sends an empty/garbage envelope to the orderer; middleware or tests construct Envelope structs with nil Payload/Signature fields in ways that fail marshaling; version mismatch where an internal protobuf type is malformed after an upgrade.","solutions":["Ensure the envelope passed to Order/Configure is non-nil before submitting","Validate the Envelope (Payload and Signature present and valid base64/bytes) on the client before broadcast","Check the wrapped proto error text (proto: Marshal called with nil) to identify which nested field is nil","Rebuild/serialize the envelope client-side with protoutil.MarshalOrPanic or CreateSignedEnvelope to guarantee a well-formed message"],"exampleFix":"// before\nc.Chain.Order(nil, seq) // -> failed to marshal request envelope\n\n// after\nenv, err := protoutil.CreateSignedEnvelope(cb.HeaderType_ENDORSER_TRANSACTION, chID, signer, tx, 0, 0)\nif err != nil { return err }\nif env == nil { return errors.New(\"nil envelope\") }\nreturn c.Chain.Order(env, seq)","handlingStrategy":"validation","validationCode":"func validEnvelope(env *cb.Envelope) bool {\n    if env == nil { return false }\n    b, err := proto.Marshal(env)\n    return err == nil && len(b) > 0\n}\nif !validEnvelope(env) { return errors.New(\"invalid envelope\") }\nreturn chain.Order(env, seq)","typeGuard":"func isEnvelope(m interface{}) (*cb.Envelope, bool) {\n    env, ok := m.(*cb.Envelope)\n    if !ok || env == nil { return nil, false }\n    return env, true\n}","tryCatchPattern":"if err := chain.Order(env, seq); err != nil {\n    if strings.Contains(err.Error(), \"failed to marshal request envelope\") {\n        return fmt.Errorf(\"envelope not marshalable: %w\", err)\n    }\n    return err\n}","preventionTips":["Always construct envelopes with protoutil.CreateSignedEnvelope, never hand-assemble structs","Nil-check envelopes before any Order/Configure call","Round-trip proto.Marshal client-side as a pre-flight sanity check","Keep protobuf library versions consistent between client and orderer"],"tags":["protobuf","serialization","orderer","smartbft"],"backgroundTag":"protobuf-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"}