{"record":{"id":"65b0efb9b8ea0076","repo":"hyperledger/fabric","slug":"chaincode-definition-for-s-is-invalid-policy-f","errorCode":null,"errorMessage":"chaincode definition for [%s] is invalid, policy field must be set","messagePattern":"chaincode definition for \\[(.+?)\\] is invalid, policy field must be set","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"core/committer/txvalidator/v20/plugindispatcher/dispatcher.go","lineNumber":259,"sourceCode":"\t}\n\tdefer qe.Done()\n\n\tplugin, args, unexpectedErr, validationErr := v.lcr.ValidationInfo(channelID, ccid, qe)\n\tif unexpectedErr != nil {\n\t\treturn \"\", nil, &commonerrors.VSCCInfoLookupFailureError{\n\t\t\tReason: fmt.Sprintf(\"Could not retrieve state for chaincode %s, error %s\", ccid, unexpectedErr),\n\t\t}\n\t}\n\tif validationErr != nil {\n\t\treturn \"\", nil, validationErr\n\t}\n\n\tif plugin == \"\" {\n\t\treturn \"\", nil, errors.Errorf(\"chaincode definition for [%s] is invalid, plugin field must be set\", ccid)\n\t}\n\n\tif len(args) == 0 {\n\t\treturn \"\", nil, errors.Errorf(\"chaincode definition for [%s] is invalid, policy field must be set\", ccid)\n\t}\n\n\treturn plugin, args, nil\n}\n\n// GetInfoForValidate gets the ChaincodeInstance(with latest version) of tx, validation plugin and policy\nfunc (v *dispatcherImpl) GetInfoForValidate(chdr *common.ChannelHeader, ccID string) (string, []byte, error) {\n\t// obtain name of the validation plugin and the policy\n\tplugin, args, err := v.getCDataForCC(chdr.ChannelId, ccID)\n\tif err != nil {\n\t\tlogger.Errorf(\"Unable to get chaincode data from ledger for txid %s, due to %s\", chdr.TxId, err)\n\t\treturn \"\", nil, err\n\t}\n\treturn plugin, args, nil\n}\n\n// txWritesToNamespace returns true if the supplied NsRwSet\n// performs a ledger write","sourceCodeStart":241,"sourceCodeEnd":277,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/committer/txvalidator/v20/plugindispatcher/dispatcher.go#L241-L277","documentation":"getCDataForCC found the chaincode definition with an empty policy arguments set (len(args) == 0). Every chaincode definition must carry validation policy arguments (typically the endorsement policy bytes); without them the validator cannot validate the tx, so it returns this error. This mirrors error 696 but for the policy field.","triggerScenarios":"Dispatch→GetInfoForValidate→getCDataForCC reads a chaincode definition whose policy/args slice is empty — e.g. LSCC record written without policy bytes, incomplete upgrade, or custom lifecycle omitting the endorsement policy.","commonSituations":"Instantiation/approval done with policy omitted and a legacy path storing empty args; manual ledger surgery on LSCC keys; migration of pre-V2 definitions losing policy data.","solutions":["Re-issue the chaincode definition with an endorsement policy (e.g. --policy \"AND('Org1MSP.peer','Org2MSP.peer')\") so args are populated.","Set a default policy (MAJORITY Endorsement) when approving the definition.","Fix custom lifecycle persistence to always store policy bytes.","If the definition is corrupt, repair or redeploy the chaincode definition on the channel."],"exampleFix":"// before\npeer chaincode instantiate -n mycc -v 1.0 -c '{\"Args\":[\"init\"]}'  // no -P\n// after\npeer chaincode instantiate -n mycc -v 1.0 -c '{\"Args\":[\"init\"]}' -P \"AND('Org1MSP.member')\"","handlingStrategy":"validation","validationCode":"const def = getChaincodeDefinition(name, version); if (!def.args || def.args.length === 0) throw new Error(`definition for ${name} missing endorsement policy args`);","typeGuard":"function hasPolicyArgs(def) { return Array.isArray(def?.args) && def.args.length > 0; }","tryCatchPattern":"try { getInfoForValidate(); } catch (err) { if (/policy field must be set/.test(err.message)) { /* re-issue definition with an endorsement policy */ } else { throw err; } }","preventionTips":["Always specify an endorsement policy on instantiate/approve.","Rely on channel default (MAJORITY Endorsement) if no custom policy is needed.","Avoid manual lifecycle persistence.","Verify definitions post-upgrade."],"tags":["hyperledger-fabric","lifecycle","endorsement-policy","configuration"],"backgroundTag":"endorsement-policy-missing","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"}