{"record":{"id":"6ebf0f2a079bcaee","repo":"hyperledger/fabric","slug":"error-marshaling-chaincodeheaderextension","errorCode":null,"errorMessage":"error marshaling ChaincodeHeaderExtension","messagePattern":"error marshaling ChaincodeHeaderExtension","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"protoutil/proputils.go","lineNumber":65,"sourceCode":"\tif err != nil {\n\t\treturn nil, \"\", err\n\t}\n\n\t// compute txid unless provided by tests\n\tif txid == \"\" {\n\t\ttxid = ComputeTxID(nonce, creator)\n\t}\n\n\treturn CreateChaincodeProposalWithTxIDNonceAndTransient(txid, typ, channelID, cis, nonce, creator, transientMap)\n}\n\n// CreateChaincodeProposalWithTxIDNonceAndTransient creates a proposal from\n// given input\nfunc CreateChaincodeProposalWithTxIDNonceAndTransient(txid string, typ common.HeaderType, channelID string, cis *peer.ChaincodeInvocationSpec, nonce, creator []byte, transientMap map[string][]byte) (*peer.Proposal, string, error) {\n\tccHdrExt := &peer.ChaincodeHeaderExtension{ChaincodeId: cis.ChaincodeSpec.ChaincodeId}\n\tccHdrExtBytes, err := proto.Marshal(ccHdrExt)\n\tif err != nil {\n\t\treturn nil, \"\", errors.Wrap(err, \"error marshaling ChaincodeHeaderExtension\")\n\t}\n\n\tcisBytes, err := proto.Marshal(cis)\n\tif err != nil {\n\t\treturn nil, \"\", errors.Wrap(err, \"error marshaling ChaincodeInvocationSpec\")\n\t}\n\n\tccPropPayload := &peer.ChaincodeProposalPayload{Input: cisBytes, TransientMap: transientMap}\n\tccPropPayloadBytes, err := proto.Marshal(ccPropPayload)\n\tif err != nil {\n\t\treturn nil, \"\", errors.Wrap(err, \"error marshaling ChaincodeProposalPayload\")\n\t}\n\n\t// TODO: epoch is now set to zero. This must be changed once we\n\t// get a more appropriate mechanism to handle it in.\n\tvar epoch uint64\n\n\thdr := &common.Header{","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/protoutil/proputils.go#L47-L83","documentation":"CreateChaincodeProposalWithTxIDNonceAndTransient builds the ChaincodeHeaderExtension (holding the chaincode ID) and protobuf-marshals it. This error wraps a proto.Marshal failure on that extension. In practice proto.Marshal of a well-formed ChaincodeHeaderExtension virtually never fails, so this indicates a nil cis / cis.ChaincodeSpec input.","triggerScenarios":"Calling CreateChaincodeProposalWithTxIDNonceAndTransient (or its wrappers CreateChaincodeProposalWithTransient, CreateChaincodeProposalWithTxIDAndTransient, CreateProposalFromCISAndTxid, ConstructSignedTxEnv) with cis == nil or cis.ChaincodeSpec == nil, which panics on the next line; a marshal failure would only occur with a corrupt protobuf registry/version mismatch of the peer proto package.","commonSituations":"Constructing proposals in SDK/CLI code where the ChaincodeInvocationSpec was forgotten or built without ChaincodeSpec; mixing incompatible github.com/hyperledger/fabric-protos versions with fabric.","solutions":["Ensure cis is non-nil with cis.ChaincodeSpec.ChaincodeId populated before calling","Build the spec with &peer.ChaincodeInvocationSpec{ChaincodeSpec: &peer.ChaincodeSpec{ChaincodeId: ccid, ...}}","Align github.com/hyperledger/fabric-protos-go versions between your code and fabric"],"exampleFix":"// before\nproposal, _, err := protoutil.CreateChaincodeProposalWithTransient(common.HeaderType_ENDORSER_TRANSACTION, \"ch\", nil, creator, transient) // nil CIS\n// after\ncis := &peer.ChaincodeInvocationSpec{ChaincodeSpec: &peer.ChaincodeSpec{ChaincodeId: &peer.ChaincodeID{Name: \"mycc\"}}}\nproposal, _, err := protoutil.CreateChaincodeProposalWithTransient(common.HeaderType_ENDORSER_TRANSACTION, \"ch\", cis, creator, transient)","handlingStrategy":"validation","validationCode":"if cis == nil || cis.ChaincodeSpec == nil || cis.ChaincodeSpec.ChaincodeId == nil {\n\treturn errors.New(\"ChaincodeInvocationSpec with ChaincodeSpec.ChaincodeId is required\")\n}","typeGuard":"func validCIS(cis *peer.ChaincodeInvocationSpec) bool {\n\treturn cis != nil && cis.ChaincodeSpec != nil && cis.ChaincodeSpec.ChaincodeId != nil && cis.ChaincodeSpec.ChaincodeId.Name != \"\"\n}","tryCatchPattern":"proposal, txid, err := protoutil.CreateChaincodeProposalWithTransient(htype, channelID, cis, creator, transient)\nif err != nil {\n\treturn fmt.Errorf(\"proposal creation failed: %w\", err) // includes marshal wrap message\n}","preventionTips":["Build CIS with ChaincodeSpec and ChaincodeID always populated","Keep github.com/hyperledger/fabric-protos-go at the version matching your fabric release","Never ignore errors from earlier proposal-construction steps before reusing their outputs"],"tags":["fabric","protobuf","marshal","chaincode-proposal"],"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"}