{"record":{"id":"94a926bef5c17b29","repo":"hyperledger/fabric","slug":"nil-config-passed-to-collection-setup","errorCode":null,"errorMessage":"Nil config passed to collection setup","messagePattern":"Nil config passed to collection setup","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/common/privdata/simplecollection.go","lineNumber":88,"sourceCode":"}\n\n// IsMemberOnlyRead returns whether only collection member\n// has the read permission\nfunc (sc *SimpleCollection) IsMemberOnlyRead() bool {\n\treturn sc.conf.MemberOnlyRead\n}\n\n// IsMemberOnlyWrite returns whether only collection member\n// has the write permission\nfunc (sc *SimpleCollection) IsMemberOnlyWrite() bool {\n\treturn sc.conf.MemberOnlyWrite\n}\n\n// Setup configures a simple collection object based on a given\n// StaticCollectionConfig proto that has all the necessary information\nfunc (sc *SimpleCollection) Setup(collectionConfig *peer.StaticCollectionConfig, deserializer msp.IdentityDeserializer) error {\n\tif collectionConfig == nil {\n\t\treturn errors.New(\"Nil config passed to collection setup\")\n\t}\n\tsc.conf = proto.Clone(collectionConfig).(*peer.StaticCollectionConfig)\n\tsc.name = collectionConfig.GetName()\n\n\t// get the access signature policy envelope\n\tcollectionPolicyConfig := collectionConfig.GetMemberOrgsPolicy()\n\tif collectionPolicyConfig == nil {\n\t\treturn errors.New(\"Collection config policy is nil\")\n\t}\n\taccessPolicyEnvelope := collectionPolicyConfig.GetSignaturePolicy()\n\tif accessPolicyEnvelope == nil {\n\t\treturn errors.New(\"Collection config access policy is nil\")\n\t}\n\n\terr := sc.setupAccessPolicy(collectionPolicyConfig, deserializer)\n\tif err != nil {\n\t\treturn err\n\t}","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/common/privdata/simplecollection.go#L70-L106","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nvar cfg *peer.StaticCollectionConfig\nsc.Setup(cfg, deserializer) // errors: Nil config passed\n\n// after\nif cfg == nil {\n  return errors.New(\"collection config missing\")\n}\nsc.Setup(cfg, deserializer)","handlingStrategy":"type-guard","validationCode":"if collectionConfig == nil {\n  return fmt.Errorf(\"collection %q not found in config package\", collName)\n}","typeGuard":"func validCollectionConfig(c *peer.StaticCollectionConfig) bool {\n  return c != nil && c.GetName() != \"\"\n}","tryCatchPattern":"sc := &privdata.SimpleCollection{}\nif err := sc.Setup(cfg, deserializer); err != nil {\n  if strings.Contains(err.Error(), \"Nil config\") {\n    return fmt.Errorf(\"collection definition missing: %w\", err)\n  }\n  return err\n}","preventionTips":["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"],"tags":["privdata","nil-check","collection-config"],"backgroundTag":"nil-required-field","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"}