{"record":{"id":"4c67b0490a304218","repo":"hyperledger/fabric","slug":"header-not-set","errorCode":null,"errorMessage":"header not set","messagePattern":"header not set","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"protoutil/commonutils.go","lineNumber":246,"sourceCode":"\t\treturn false\n\t}\n\n\treturn cb.HeaderType(hdr.Type) == cb.HeaderType_CONFIG\n}\n\n// ChannelHeader returns the *cb.ChannelHeader for a given *cb.Envelope.\nfunc ChannelHeader(env *cb.Envelope) (*cb.ChannelHeader, error) {\n\tif env == nil {\n\t\treturn nil, errors.New(\"Invalid envelope payload. can't be nil\")\n\t}\n\n\tenvPayload, err := UnmarshalPayload(env.Payload)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tif envPayload.Header == nil {\n\t\treturn nil, errors.New(\"header not set\")\n\t}\n\n\tif envPayload.Header.ChannelHeader == nil {\n\t\treturn nil, errors.New(\"channel header not set\")\n\t}\n\n\tchdr, err := UnmarshalChannelHeader(envPayload.Header.ChannelHeader)\n\tif err != nil {\n\t\treturn nil, errors.WithMessage(err, \"error unmarshalling channel header\")\n\t}\n\n\treturn chdr, nil\n}\n\n// ChannelID returns the Channel ID for a given *cb.Envelope.\nfunc ChannelID(env *cb.Envelope) (string, error) {\n\tchdr, err := ChannelHeader(env)\n\tif err != nil {","sourceCodeStart":228,"sourceCodeEnd":264,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/protoutil/commonutils.go#L228-L264","documentation":"ChannelHeader() extracts the common.ChannelHeader from an envelope. This error is thrown when the envelope's payload was successfully unmarshaled but its Header field is nil, meaning the envelope carries no header at all. The library refuses to proceed because every envelope in Fabric must carry a header identifying channel, type, and creator.","triggerScenarios":"Calling protoutil.ChannelID, protoutil.BroadcastChannelSupport, protoutil.ConfigChannelHeader, protoutil.ConfigEnvelopeFromBlock, or protoutil.ChannelHeader with an *cb.Envelope whose payload deserializes to a *cb.Payload with Header == nil (e.g. an envelope built manually with only Payload set, or a payload that is not a TxPayload/ConfigPayload shape).","commonSituations":"Hand-crafting envelopes in tests or CLI tools without calling protoutil.CreateEnvelope; receiving malformed envelopes over the network from a misbehaving client; blocks/data produced by an older or incompatible Fabric version; passing a non-payload (e.g. marshaled different message) as env.Payload so Header is absent.","solutions":["Construct envelopes with protoutil.CreateEnvelope(payload, signer) or via protoutil.CreateSignedEnvelope so the header is populated","Verify the envelope source: call UnmarshalPayload yourself and check Payload.Header != nil before calling ChannelHeader","Check ChannelHeader(payload.Header) exists on the payload actually sent; fix the producer of the envelope","If consuming blocks, confirm the block was produced by a compatible Fabric version"],"exampleFix":"// before\nenv := &common.Envelope{Payload: payloadBytes}\nchdr, err := protoutil.ChannelHeader(env) // panics path: \"header not set\"\n// after\npayload := &common.Payload{Header: &common.Header{ChannelHeader: chdrBytes, SignatureHeader: sigHdrBytes}, Data: data}\nenv, err := protoutil.CreateEnvelope(payload, signer)\nchdr, err := protoutil.ChannelHeader(env)","handlingStrategy":"validation","validationCode":"payload, err := protoutil.UnmarshalPayload(env.Payload)\nif err != nil { return err }\nif payload == nil || payload.Header == nil { return errors.New(\"envelope payload has no header\") }\nchdr, err := protoutil.ChannelHeader(env)","typeGuard":"func hasHeader(env *common.Envelope) bool {\n\tp, err := protoutil.UnmarshalPayload(env.GetPayload())\n\treturn err == nil && p != nil && p.Header != nil\n}","tryCatchPattern":"chdr, err := protoutil.ChannelHeader(env)\nif err != nil {\n\tif err.Error() == \"header not set\" || err.Error() == \"channel header not set\" {\n\t\treturn fmt.Errorf(\"malformed envelope from producer %s: %w\", peerID, err)\n\t}\n\treturn err\n}","preventionTips":["Always create envelopes with protoutil.CreateEnvelope / CreateSignedEnvelope, never by hand","Validate envelope structure at ingest boundaries before processing","Log raw envelope bytes when this error occurs to identify the producer","Keep Fabric versions consistent across peers and clients"],"tags":["fabric","protobuf","missing-header","envelope"],"backgroundTag":"missing-required-argument","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"}