hyperledger/fabric · error
Nil config passed to collection setup
Error message
Nil config passed to collection setup
What it means
SimpleCollection.Setup builds a private-data collection from a StaticCollectionConfig proto and requires a non-nil config. This error means a nil collection configuration was handed to Setup, so there is nothing to configure. It is a defensive guard preventing nil-pointer dereference when cloning and reading the config.
Source
Thrown at core/common/privdata/simplecollection.go:88
}
// IsMemberOnlyRead returns whether only collection member
// has the read permission
func (sc *SimpleCollection) IsMemberOnlyRead() bool {
return sc.conf.MemberOnlyRead
}
// IsMemberOnlyWrite returns whether only collection member
// has the write permission
func (sc *SimpleCollection) IsMemberOnlyWrite() bool {
return sc.conf.MemberOnlyWrite
}
// Setup configures a simple collection object based on a given
// StaticCollectionConfig proto that has all the necessary information
func (sc *SimpleCollection) Setup(collectionConfig *peer.StaticCollectionConfig, deserializer msp.IdentityDeserializer) error {
if collectionConfig == nil {
return errors.New("Nil config passed to collection setup")
}
sc.conf = proto.Clone(collectionConfig).(*peer.StaticCollectionConfig)
sc.name = collectionConfig.GetName()
// get the access signature policy envelope
collectionPolicyConfig := collectionConfig.GetMemberOrgsPolicy()
if collectionPolicyConfig == nil {
return errors.New("Collection config policy is nil")
}
accessPolicyEnvelope := collectionPolicyConfig.GetSignaturePolicy()
if accessPolicyEnvelope == nil {
return errors.New("Collection config access policy is nil")
}
err := sc.setupAccessPolicy(collectionPolicyConfig, deserializer)
if err != nil {
return err
}View on GitHub (pinned to 2736b63f8f)
Solutions
- Pass a valid, populated *peer.StaticCollectionConfig to Setup/NewSimpleCollection
- Validate the collection config package (all referenced collections defined) before endorser processing
- Fix the chaincode's collections.json/collection config so the requested collection exists
Example fix
// before
var cfg *peer.StaticCollectionConfig
sc.Setup(cfg, deserializer) // errors: Nil config passed
// after
if cfg == nil {
return errors.New("collection config missing")
}
sc.Setup(cfg, deserializer) Defensive patterns
Strategy: type-guard
Validate before calling
if collectionConfig == nil {
return fmt.Errorf("collection %q not found in config package", collName)
} Type guard
func validCollectionConfig(c *peer.StaticCollectionConfig) bool {
return c != nil && c.GetName() != ""
} Try / catch
sc := &privdata.SimpleCollection{}
if err := sc.Setup(cfg, deserializer); err != nil {
if strings.Contains(err.Error(), "Nil config") {
return fmt.Errorf("collection definition missing: %w", err)
}
return err
} Prevention
- Validate collections.json before packaging/approving chaincode
- Fail fast when a collection lookup by name yields nil
- Add unit tests asserting every referenced collection exists in the package
When it happens
Trigger: Calling NewSimpleCollection or Setup with a nil *peer.StaticCollectionConfig — e.g., a collection definition missing from the collection config package, or code that indexes into a config slice without checking presence.
Common situations: Malformed collection configuration in chaincode definition approval, a collection name typo causing lookup failure that yields nil, or hand-built collection config packages in tests/tools.
Related errors
- Collection config policy is nil
- Collection config access policy is nil
- invalid configuration for collection criteria %#v
- collection policy config is nil
- collection config access policy is nil
AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04).
Data as JSON: /api/errors/94a926bef5c17b29.
Report an issue: GitHub.