{"record":{"id":"41f7376f4cd34bfa","repo":"hyperledger/fabric","slug":"failed-to-parse-collection-config","errorCode":null,"errorMessage":"failed to parse collection config","messagePattern":"failed to parse collection config","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/cclifecycle/util.go","lineNumber":72,"sourceCode":"\t\t\tPolicy:  ccInfo.Policy,\n\t\t}\n\n\t\tif !filter(instCC) {\n\t\t\tLogger.Debug(\"Filtered out\", instCC)\n\t\t\tcontinue\n\t\t}\n\n\t\tif loadCollections {\n\t\t\tkey := privdata.BuildCollectionKVSKey(cc)\n\t\t\tcollectionData, err := q.GetState(\"lscc\", key)\n\t\t\tif err != nil {\n\t\t\t\tLogger.Errorf(\"Failed querying lscc namespace for %s: %v\", key, err)\n\t\t\t\treturn nil, errors.WithStack(err)\n\t\t\t}\n\t\t\tccp, err := privdata.ParseCollectionConfig(collectionData)\n\t\t\tif err != nil {\n\t\t\t\tLogger.Errorf(\"failed to parse collection config, error %s\", err.Error())\n\t\t\t\treturn nil, errors.Wrapf(err, \"failed to parse collection config\")\n\t\t\t}\n\t\t\tinstCC.CollectionsConfig = ccp\n\t\t\tLogger.Debug(\"Retrieved collection config for\", cc, \"from\", key)\n\t\t}\n\n\t\tres = append(res, instCC)\n\t}\n\tLogger.Debug(\"Returning\", res)\n\treturn res, nil\n}\n\nfunc deployedCCToNameVersion(cc chaincode.Metadata) nameVersion {\n\treturn nameVersion{\n\t\tname:    cc.Name,\n\t\tversion: cc.Version,\n\t}\n}\n","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/cclifecycle/util.go#L54-L90","documentation":"When DeployedChaincodes gathers metadata for deployed chaincodes it reads each chaincode's collection configuration from LSCC and parses it with privdata.ParseCollectionConfig. If the stored collection config bytes cannot be unmarshaled/validated, the error is wrapped as 'failed to parse collection config' and the whole metadata query fails.","triggerScenarios":"Metadata() -> DeployedChaincodes iterating LSCC keys where the collectionData value stored under an LSCC collection config key is not a valid CollectionConfigPackage protobuf.","commonSituations":"State database corruption or manual edits to LSCC keys; chaincode deployed by a non-standard/older toolchain writing an unexpected format; reading a key that collides with a collection-config naming pattern but holds different data.","solutions":["Read the underlying cause (Log the wrapped error) to see the unmarshal failure detail.","Verify the chaincode's collection config in the channel state via `peer chaincode query` / qscc and, if corrupt, redeploy the chaincode with a valid collection configuration.","Check for version incompatibility between the peer parsing the config and the node that wrote it (upgrade peers to a consistent version).","If a stale/colliding key exists in LSCC, purge it via proper channel admin tooling rather than direct state edits."],"exampleFix":"// before: deploying with a malformed collection spec JSON\npeer lifecycle chaincode approveformyorg --collections-config bad.json\n// after: validate the collection config file parses\npeer lifecycle chaincode approveformyorg --collections-config collections.json # with valid CollectionConfigPackage JSON","handlingStrategy":"try-catch","validationCode":"// pre-validate collection config file before deployment\nvar ccp peer.CollectionConfigPackage\nif err := json.Unmarshal(cfgJSON, &ccp); err != nil {\n    return fmt.Errorf(\"invalid collections config: %w\", err)\n}","typeGuard":"func isParsableCollectionConfig(raw []byte) bool {\n    var ccp common.CollectionConfigPackage\n    return proto.Unmarshal(raw, &ccp) == nil\n}","tryCatchPattern":"mets, err := metadataMgr.Metadata(channelID, ccName)\nif err != nil {\n    if strings.Contains(err.Error(), \"failed to parse collection config\") {\n        // treat state as corrupt: redeploy chaincode or rebuild state from blocks\n    }\n}","preventionTips":["Validate collection config JSON with the peer tooling before approveformyorg","Never hand-edit LSCC entries in the state database","Keep peer versions uniform across the network when state is restored or migrated"],"tags":["hyperledger-fabric","lifecycle","collections","protobuf","state-database"],"backgroundTag":"collection-config-parse-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"}