{"record":{"id":"e4422b98510f5823","repo":"hyperledger/fabric","slug":"unable-to-check-whether-collection-existed-earlier-e4422b","errorCode":null,"errorMessage":"unable to check whether collection existed earlier for chaincode %s:%s: %v","messagePattern":"unable to check whether collection existed earlier for chaincode (.+?):(.+?): (.+?)","errorType":"exception","errorClass":"VSCCExecutionFailureError","httpStatus":null,"severity":"error","filePath":"core/handlers/validation/builtin/v12/validation_logic.go","lineNumber":462,"sourceCode":"\n\tif ac.V1_2Validation() {\n\t\tnewCollectionConfigs := newCollectionConfigPackage.GetConfig()\n\t\tif err := validateNewCollectionConfigs(newCollectionConfigs); err != nil {\n\t\t\treturn policyErr(err)\n\t\t}\n\n\t\tif lsccFunc == lscc.UPGRADE {\n\n\t\t\tcollectionCriteria := privdata.CollectionCriteria{Channel: channelName, Namespace: cdRWSet.Name}\n\t\t\t// oldCollectionConfigPackage denotes the existing collection config package in the ledger\n\t\t\toldCollectionConfigPackage, err := privdata.RetrieveCollectionConfigPackageFromState(collectionCriteria, state)\n\t\t\tif err != nil {\n\t\t\t\t// fail if we get any error other than NoSuchCollectionError\n\t\t\t\t// because it means something went wrong while looking up the\n\t\t\t\t// older collection\n\t\t\t\tif _, ok := err.(privdata.NoSuchCollectionError); !ok {\n\t\t\t\t\treturn &commonerrors.VSCCExecutionFailureError{\n\t\t\t\t\t\tErr: fmt.Errorf(\"unable to check whether collection existed earlier for chaincode %s:%s: %v\",\n\t\t\t\t\t\t\tcdRWSet.Name, cdRWSet.Version, err),\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// oldCollectionConfigPackage denotes the existing collection config package in the ledger\n\t\t\tif oldCollectionConfigPackage != nil {\n\t\t\t\toldCollectionConfigs := oldCollectionConfigPackage.GetConfig()\n\t\t\t\tif err := validateNewCollectionConfigsAgainstOld(newCollectionConfigs, oldCollectionConfigs); err != nil {\n\t\t\t\t\treturn policyErr(err)\n\t\t\t\t}\n\n\t\t\t}\n\t\t}\n\t}\n\n\treturn nil\n}","sourceCodeStart":444,"sourceCodeEnd":480,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/handlers/validation/builtin/v12/validation_logic.go#L444-L480","documentation":"On lscc UPGRADE with V1_2 validation enabled, VSCC looks up the previous collection config package from ledger state via privdata.RetrieveCollectionConfigPackageFromState. This error is wrapped in a VSCCExecutionFailureError and means the ledger lookup itself failed with something other than NoSuchCollectionError — i.e. an internal/state-access failure, not a missing collection. Unlike policy errors this signals a validation-system execution failure.","triggerScenarios":"During UPGRADE validation on a channel with private data, RetrieveCollectionConfigPackageFromState returns a non-NoSuchCollectionError (e.g. state/db access error, deserialization failure of the stored config package) while checking whether collections existed earlier for chaincode name:version.","commonSituations":"Corrupted or partially-written private data state in the ledger; LevelDB/CouchDB I/O errors during validation; state listener inconsistency after peer crash or snapshot restore; bugs when the old chaincode was deployed on an incompatible fabric version.","solutions":["Inspect peer logs for the underlying error from RetrieveCollectionConfigPackageFromState to identify the state/db failure.","Verify ledger/state DB health (LevelDB/CouchDB reachable and not corrupted); run peer db checks or rebuild state from blocks if corrupted.","If state is corrupt, resync the peer from genesis or from a snapshot taken from a healthy peer.","Retry endorsement/validation after fixing transient DB issues; as a VSCCExecutionFailureError the tx failure is environmental rather than a policy violation.","Ensure the prior chaincode was deployed with a compatible fabric version so stored config packages deserialize correctly."],"exampleFix":"// before: ignoring ledger health, re-submitting the upgrade repeatedly\npeer chaincode upgrade -C mychannel ... --collections-config cc.json\n// after: fix/verify state DB first, then retry\n# e.g. check CouchDB is up, then re-run the upgrade","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"// distinguish policy vs execution failure on the client/peer side\nvar vsccErr *commonerrors.VSCCExecutionFailureError\nif errors.As(err, &vsccErr) {\n    // transient/ledger issue: retry after checking state DB health\n    retryUpgradeWithBackoff()\n} else {\n    // policy error: fix the transaction payload, don't retry blindly\n}","preventionTips":["Monitor peer state DB (LevelDB/CouchDB) health before running upgrades.","Keep all peers on the same fabric patch version.","Back up / snapshot ledger state before chaincode upgrades.","Gracefully handle NoSuchCollectionError as 'first deploy' rather than a fault."],"tags":["hyperledger-fabric","vscc","ledger","private-data","state-db"],"backgroundTag":"state-lookup-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"}