{"record":{"id":"2ccb4806c13169da","repo":"hyperledger/fabric","slug":"could-not-fetch-chaincode-source-metadata-for-s","errorCode":null,"errorMessage":"could not fetch chaincode-source metadata for %s","messagePattern":"could not fetch chaincode-source metadata for (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/chaincode/lifecycle/lifecycle.go","lineNumber":638,"sourceCode":"\tprivateName := fmt.Sprintf(\"%s#%d\", ccname, sequence)\n\t// Verify that metadata type is chaincode parameters type\n\tif metadata.Datatype != ChaincodeParametersType {\n\t\treturn nil, errors.Errorf(\"not a chaincode parameters type: %s\", metadata.Datatype)\n\t}\n\n\t// Get chaincode parameters for the requested sequence\n\tccParameters := &ChaincodeParameters{}\n\tif err := ef.Resources.Serializer.Deserialize(NamespacesName, privateName, metadata, ccParameters, orgState); err != nil {\n\t\treturn nil, errors.WithMessagef(err, \"could not deserialize chaincode parameters for %s\", privateName)\n\t}\n\n\t// Get package ID for the requested sequence\n\tmetadata, ok, err := ef.Resources.Serializer.DeserializeMetadata(ChaincodeSourcesName, privateName, orgState)\n\tif err != nil {\n\t\treturn nil, errors.WithMessagef(err, \"could not deserialize chaincode-source metadata for %s\", privateName)\n\t}\n\tif !ok {\n\t\treturn nil, errors.Errorf(\"could not fetch chaincode-source metadata for %s\", privateName)\n\t}\n\tif metadata.Datatype != ChaincodeLocalPackageType {\n\t\treturn nil, errors.Errorf(\"not a chaincode local package type: %s\", metadata.Datatype)\n\t}\n\n\tccLocalPackage := &ChaincodeLocalPackage{}\n\tif err := ef.Resources.Serializer.Deserialize(ChaincodeSourcesName, privateName, metadata, ccLocalPackage, orgState); err != nil {\n\t\treturn nil, errors.WithMessagef(err, \"could not deserialize chaincode package for %s\", privateName)\n\t}\n\n\t// Convert to lb.ChaincodeSource\n\t// An empty package ID means that the chaincode won't be invocable\n\tvar ccsrc *lb.ChaincodeSource\n\tif ccLocalPackage.PackageID != \"\" {\n\t\tccsrc = &lb.ChaincodeSource{\n\t\t\tType: &lb.ChaincodeSource_LocalPackage{\n\t\t\t\tLocalPackage: &lb.ChaincodeSource_Local{\n\t\t\t\t\tPackageId: ccLocalPackage.PackageID,","sourceCodeStart":620,"sourceCodeEnd":656,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/chaincode/lifecycle/lifecycle.go#L620-L656","documentation":"This error is thrown by the lifecycle approved-chaincode lookup when the chaincode-source metadata key (e.g. <name>#<sequence> in the org's private collection state) cannot be found during deserialization. The serializer reported no entry exists for that private name, meaning the peer does not have the approved chaincode definition recorded for that sequence. It surfaces to users as 'could not fetch chaincode-source metadata for <name>#<seq>' from QueryApprovedChaincodeDefinition(s).","triggerScenarios":"Calling QueryApprovedChaincodeDefinition/QueryApprovedChaincodeDefinitions for a name+sequence that the local org never approved, or querying with the wrong sequence number, or the org's metadata key is missing from its collection state (approval exists under a different sequence).","commonSituations":"Operator runs peer lifecycle chaincode queryapproved without first running approveformyorg on this peer; sequence number incremented but the new approval not committed on this org; querying on a different org's peer that has not approved; typo in chaincode name.","solutions":["Run 'peer lifecycle chaincode approveformyorg' for the exact name and sequence on this org before querying","Verify the sequence number with 'peer lifecycle chaincode checkcommitreadiness' or querycommitted to see the committed sequence","Confirm you are querying the peer of the org whose approval you expect; approvals are org-private","Check the chaincode name spelling matches exactly what was approved"],"exampleFix":"// before: query before approval\npeer lifecycle chaincode queryapproved --channelID mychannel --name mycc\n// error\n// after: approve first, then query\npeer lifecycle chaincode approveformyorg -C mychannel --name mycc --version 1.0 --sequence 1 --package-id <pkgID>\npeer lifecycle chaincode queryapproved -C mychannel --name mycc","handlingStrategy":"validation","validationCode":"// Before querying, verify the org approved this name+sequence:\n// peer lifecycle chaincode checkcommitreadiness -C mychannel --name mycc --version 1.0 --sequence 1\n// exit code / output shows which orgs approved; only query where your org shows true.\nconst approved = checkCommitReadinessOutput.Approvals[orgMSP];\nif (approved !== true) throw new Error('approveformyorg required before queryapproved');","typeGuard":null,"tryCatchPattern":"try {\n  def := lifecycle.QueryApprovedChaincodeDefinition(channel, name, seq)\n} catch (err) {\n  if strings.Contains(err.Error(), \"could not fetch chaincode-source metadata\") {\n    // treat as 'not approved on this org'\n  }\n}","preventionTips":["Always run approveformyorg before queryapproved","Double-check the sequence number matches your approval","Query the peer belonging to the approving org","Script checkcommitreadiness into deployment pipelines"],"tags":["fabric","lifecycle","chaincode-approval","missing-metadata"],"backgroundTag":"chaincode-not-approved","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"}