{"record":{"id":"368904b23a92696a","repo":"hyperledger/fabric","slug":"error-unmarshalling-to-implicitmetapolicy-s","errorCode":null,"errorMessage":"Error unmarshalling to ImplicitMetaPolicy: %s","messagePattern":"Error unmarshalling to ImplicitMetaPolicy: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"common/policies/implicitmeta.go","lineNumber":33,"sourceCode":"\t\"github.com/hyperledger/fabric/protoutil\"\n\t\"go.uber.org/zap/zapcore\"\n\t\"google.golang.org/protobuf/proto\"\n)\n\ntype ImplicitMetaPolicy struct {\n\tThreshold   int\n\tSubPolicies []Policy\n\n\t// Only used for logging\n\tmanagers      map[string]*ManagerImpl\n\tSubPolicyName string\n}\n\n// NewImplicitMetaPolicy creates a new policy based on the policy bytes\nfunc NewImplicitMetaPolicy(data []byte, managers map[string]*ManagerImpl) (*ImplicitMetaPolicy, error) {\n\tdefinition := &cb.ImplicitMetaPolicy{}\n\tif err := proto.Unmarshal(data, definition); err != nil {\n\t\treturn nil, fmt.Errorf(\"Error unmarshalling to ImplicitMetaPolicy: %s\", err)\n\t}\n\n\tsubPolicies := make([]Policy, len(managers))\n\n\ti := 0\n\tfor _, manager := range managers {\n\t\tsubPolicies[i], _ = manager.GetPolicy(definition.SubPolicy)\n\t\ti++\n\t}\n\n\tvar threshold int\n\n\tswitch definition.Rule {\n\tcase cb.ImplicitMetaPolicy_ANY:\n\t\tthreshold = 1\n\tcase cb.ImplicitMetaPolicy_ALL:\n\t\tthreshold = len(subPolicies)\n\tcase cb.ImplicitMetaPolicy_MAJORITY:","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/common/policies/implicitmeta.go#L15-L51","documentation":"NewImplicitMetaPolicy expects the policy bytes to unmarshal into a cb.ImplicitMetaPolicy protobuf. If proto.Unmarshal fails, the bytes are not a valid ImplicitMetaPolicy (wrong message type, corrupt data, or wrong encoding), so this error is returned instead of a policy object.","triggerScenarios":"Calling NewImplicitMetaPolicy with bytes produced from a different protobuf message (e.g. a SignaturePolicyEnvelope marshaled where ImplicitMetaPolicy is expected), truncated/corrupted stored policy bytes, or hand-crafted policy data in tests (TestImplicitMarshalError).","commonSituations":"configtx.yaml policy Type/Rule mismatch so the wrong policy struct is marshaled; corrupted policy bytes in a channel config block; custom MSP/policy code marshaling the wrong message; version mismatch where the field layout changed.","solutions":["Ensure the marshaled bytes are actually a cb.ImplicitMetaPolicy — check the config policy Type is ImplicitMeta with a valid Rule","Validate the channel config with configtxgen/configtxlator before submission","Inspect/recover the corrupted policy bytes from the channel config block if stored data is damaged","Check that the policy name in configtx maps to the intended policy type (Signature vs ImplicitMeta)"],"exampleFix":"// before\npolBytes := pb.Marshal(sigPolicyEnvelope) // wrong type\nimp, err := policies.NewImplicitMetaPolicy(polBytes, managers)\n// after\nimpDef := &cb.ImplicitMetaPolicy{Rule: cb.ImplicitMetaPolicy_ANY, SubPolicyName: \"Readers\"}\npolBytes, _ := proto.Marshal(impDef)\nimp, err := policies.NewImplicitMetaPolicy(polBytes, managers)","handlingStrategy":"try-catch","validationCode":"func looksLikeImplicitMetaPolicy(data []byte) error {\n\td := &cb.ImplicitMetaPolicy{}\n\treturn proto.Unmarshal(data, d) // same check the library performs\n}","typeGuard":"func isValidPolicyBytes(data []byte) bool {\n\tp := &cb.ImplicitMetaPolicy{}\n\treturn proto.Unmarshal(data, p) == nil && p.SubPolicyName != \"\"\n}","tryCatchPattern":"pol, err := policies.NewImplicitMetaPolicy(data, managers)\nif err != nil {\n\tif strings.Contains(err.Error(), \"Error unmarshalling to ImplicitMetaPolicy\") {\n\t\tlog.Errorf(\"policy bytes are not ImplicitMetaPolicy proto: %v\", err)\n\t}\n\treturn err\n}","preventionTips":["Marshal exactly cb.ImplicitMetaPolicy for implicit-meta policy configs","Match configtx policy Type (ImplicitMeta vs Signature) with the expected struct","Validate channel config with configtxlator before submission","Treat corrupted stored policy bytes as corruption: verify against the genesis block"],"tags":["policies","protobuf","deserialization","fabric"],"backgroundTag":"protobuf-unmarshal-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"}