{"record":{"id":"b105e1ecdd633a2f","repo":"hyperledger/fabric","slug":"nil-envelope","errorCode":null,"errorMessage":"nil envelope","messagePattern":"nil envelope","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gossip/protoext/signing.go","lineNumber":62,"sourceCode":"\n// NoopSign creates a SignedGossipMessage with a nil signature\nfunc NoopSign(m *gossip.GossipMessage) (*SignedGossipMessage, error) {\n\tsigner := func(msg []byte) ([]byte, error) {\n\t\treturn nil, nil\n\t}\n\tsMsg := &SignedGossipMessage{\n\t\tGossipMessage: m,\n\t}\n\t_, err := sMsg.Sign(signer)\n\treturn sMsg, err\n}\n\n// EnvelopeToGossipMessage un-marshals a given envelope and creates a\n// SignedGossipMessage out of it.\n// Returns an error if un-marshaling fails.\nfunc EnvelopeToGossipMessage(e *gossip.Envelope) (*SignedGossipMessage, error) {\n\tif e == nil {\n\t\treturn nil, errors.New(\"nil envelope\")\n\t}\n\tmsg := &gossip.GossipMessage{}\n\terr := proto.Unmarshal(e.Payload, msg)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"Failed unmarshalling GossipMessage from envelope: %v\", err)\n\t}\n\treturn &SignedGossipMessage{\n\t\tGossipMessage: msg,\n\t\tEnvelope:      e,\n\t}, nil\n}\n\n// InternalEndpoint returns the internal endpoint in the secret envelope, or an\n// empty string if a failure occurs.\nfunc InternalEndpoint(s *gossip.SecretEnvelope) string {\n\tif s == nil {\n\t\treturn \"\"\n\t}","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/gossip/protoext/signing.go#L44-L80","documentation":"Sentinel guard in EnvelopeToGossipMessage: the caller passed a nil *gossip.Envelope, so there is nothing to unmarshal into a SignedGossipMessage. It is a defensive check against nil input, not a deserialization failure.","triggerScenarios":"Calling EnvelopeToGossipMessage(nil) — typically when iterating connection/membership structures that can contain nil envelopes, or when an earlier unwrap returned nil without being checked.","commonSituations":"Gossip membership/discovery code processing envelopes from peers where a field was never set; test helpers building peer lists with missing envelopes; callers ignoring a nil result from an upstream accessor.","solutions":["Check the envelope for nil before calling EnvelopeToGossipMessage and skip nil entries","Fix the producer that inserted a nil envelope into the collection","Make the caller return/propagate a sentinel error instead of dereferencing nil"],"exampleFix":"// before\nmsg, err := protoext.EnvelopeToGossipMessage(env)\n// after\nif env == nil {\n    return nil, errors.New(\"missing envelope\")\n}\nmsg, err := protoext.EnvelopeToGossipMessage(env)","handlingStrategy":"type-guard","validationCode":"if env == nil {\n    continue // skip nil envelopes in membership lists\n}","typeGuard":"func isNilEnvelope(e *gossip.Envelope) bool { return e == nil }","tryCatchPattern":"msg, err := protoext.EnvelopeToGossipMessage(env)\nif err != nil {\n    if err.Error() == \"nil envelope\" {\n        return nil, fmt.Errorf(\"peer %s has no envelope\", peerID)\n    }\n    return nil, err\n}","preventionTips":["Check for nil before unwrapping envelopes from upstream APIs","Never insert nil envelopes into membership/connection collections","Skip-and-log nil entries when iterating peer lists"],"tags":["gossip","hyperledger-fabric","nil-argument"],"backgroundTag":"nil-envelope","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"}