{"record":{"id":"9ba3300c4c1a73db","repo":"hyperledger/fabric","slug":"policy-not-found","errorCode":null,"errorMessage":"policy not found","messagePattern":"policy not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"discovery/endorsement/endorsement.go","lineNumber":268,"sourceCode":"\n\t\tlogger.Debugf(\"Merging state based policies: %v --> %v\", stateBasedCPS, stateBasedPrincipalSet)\n\n\t\treturn stateBasedPrincipalSet, nil\n\t}\n\n\tlogger.Debugf(\"No state based policies requested\")\n\n\treturn nil, nil\n}\n\nfunc (ea *endorsementAnalyzer) computePrincipalSets(channelID common.ChannelID, interest *peer.ChaincodeInterest) (policies.PrincipalSets, error) {\n\tsessionLogger := logger.With(\"channel\", string(channelID))\n\tvar inquireablePoliciesForChaincodeAndCollections []policies.InquireablePolicy\n\tfor _, chaincode := range interest.Chaincodes {\n\t\tpolicies := ea.PoliciesByChaincode(string(channelID), chaincode.Name, chaincode.CollectionNames...)\n\t\tif len(policies) == 0 {\n\t\t\tsessionLogger.Debug(\"Policy for chaincode '\", chaincode, \"'doesn't exist\")\n\t\t\treturn nil, errors.New(\"policy not found\")\n\t\t}\n\t\tif chaincode.DisregardNamespacePolicy && len(chaincode.KeyPolicies) == 0 && len(policies) == 1 {\n\t\t\tsessionLogger.Warnf(\"Client requested to disregard chaincode %s's policy, but it did not specify any \"+\n\t\t\t\t\"collection policies or key policies. This is probably a bug in the client side code, as the client should\"+\n\t\t\t\t\"either not specify DisregardNamespacePolicy, or specify at least one key policy or at least one collection policy\", chaincode.Name)\n\t\t\treturn nil, errors.Errorf(\"requested to disregard chaincode %s's policy but key and collection policies are missing, either \"+\n\t\t\t\t\"disable DisregardNamespacePolicy or specify at least one key policy or at least one collection policy\", chaincode.Name)\n\t\t}\n\t\tif chaincode.DisregardNamespacePolicy {\n\t\t\tif len(policies) == 1 {\n\t\t\t\tsessionLogger.Debugf(\"Client requested to disregard the namespace policy for chaincode %s,\"+\n\t\t\t\t\t\" and no collection policies are present\", chaincode.Name)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tsessionLogger.Debugf(\"Client requested to disregard the namespace policy for chaincode %s,\"+\n\t\t\t\t\" however there exist %d collection policies taken into account\", chaincode.Name, len(policies)-1)\n\t\t\tpolicies = policies[1:]\n\t\t}","sourceCodeStart":250,"sourceCodeEnd":286,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/discovery/endorsement/endorsement.go#L250-L286","documentation":"Thrown by computePrincipalSets when PoliciesByChaincode returns no inquireable policies for a chaincode (and its collections) on the given channel. This means the discovery service has no endorsement policy registered for that chaincode namespace, usually because the chaincode is not installed/committed (or not known) on the peers serving discovery, so no principal sets can be computed for endorsement selection.","triggerScenarios":"Calling PeersForEndorsement with a ChaincodeInterest whose Chaincodes include a chaincode.Name for which the local peer's lifecycle reports zero policies — chaincode not installed, not committed on the channel, wrong channel, or (pre-v2) not instantiated.","commonSituations":"Typo in the chaincode name; querying the wrong channel; chaincode committed only on another peer; using discovery before chaincode commit completes; lifecycle mismatch between _lifecycle and legacy LSCC in mixed-version networks.","solutions":["Verify the chaincode name spelling and that the query targets the correct channel","Confirm the chaincode is installed and committed on the peers responding to discovery (peer lifecycle chaincode querycommitted)","Re-check after commit completes / peer gossip syncs definitions","If using collections, ensure collection names passed to the query are defined in the committed collection config"],"exampleFix":"// before\ndiscoveryCli.PeersForEndorsement(ctx, interestWith(\"asset-transfer2\")) // typo\n// after\ndiscoveryCli.PeersForEndorsement(ctx, interestWith(\"asset-transfer\"))","handlingStrategy":"validation","validationCode":"committed, _ := lc.QueryCommitted(ctx, channel, ccName)\nif len(committed) == 0 { return fmt.Errorf(\"chaincode %s not committed on %s\", ccName, channel) }","typeGuard":"func chaincodeKnown(name string, committed []lifecycle.ChaincodeDefinition) bool {\n  for _, c := range committed { if c.Name == name { return true } }\n  return false\n}","tryCatchPattern":"peers, err := client.PeersForEndorsement(ctx, interest)\nif err != nil && strings.Contains(err.Error(), \"policy not found\") {\n  // verify chaincode name/channel and commit state before retry\n}","preventionTips":["Verify chaincode names against querycommitted output before discovery calls","Target the correct channel in every discovery request","Wait for commit to finish before issuing PeersForEndorsement"],"tags":["fabric","discovery","chaincode","policy-not-found"],"backgroundTag":"chaincode-not-found","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"}