{"record":{"id":"59f23f3a7b43f367","repo":"hyperledger/fabric","slug":"error-unmarshalling-to-signaturepolicy-s","errorCode":null,"errorMessage":"Error unmarshalling to SignaturePolicy: %s","messagePattern":"Error unmarshalling to SignaturePolicy: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"common/cauthdsl/policy.go","lineNumber":35,"sourceCode":"\t\"google.golang.org/protobuf/proto\"\n)\n\ntype provider struct {\n\tdeserializer msp.IdentityDeserializer\n}\n\n// NewPolicyProvider provides a policy generator for cauthdsl type policies\nfunc NewPolicyProvider(deserializer msp.IdentityDeserializer) policies.Provider {\n\treturn &provider{\n\t\tdeserializer: deserializer,\n\t}\n}\n\n// NewPolicy creates a new policy based on the policy bytes\nfunc (pr *provider) NewPolicy(data []byte) (policies.Policy, proto.Message, error) {\n\tsigPolicy := &cb.SignaturePolicyEnvelope{}\n\tif err := proto.Unmarshal(data, sigPolicy); err != nil {\n\t\treturn nil, nil, fmt.Errorf(\"Error unmarshalling to SignaturePolicy: %s\", err)\n\t}\n\n\tif sigPolicy.Version != 0 {\n\t\treturn nil, nil, fmt.Errorf(\"This evaluator only understands messages of version 0, but version was %d\", sigPolicy.Version)\n\t}\n\n\tcompiled, err := compile(sigPolicy.Rule, sigPolicy.Identities)\n\tif err != nil {\n\t\treturn nil, nil, err\n\t}\n\n\treturn &policy{\n\t\tevaluator:               compiled,\n\t\tdeserializer:            pr.deserializer,\n\t\tsignaturePolicyEnvelope: sigPolicy,\n\t}, sigPolicy, nil\n}\n","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/common/cauthdsl/policy.go#L17-L53","documentation":"provider.NewPolicy expects the stored policy bytes to be a protobuf-encoded cb.SignaturePolicyEnvelope. proto.Unmarshal failure triggers this wrapped error, so the bytes are not a valid SignaturePolicyEnvelope.","triggerScenarios":"NewManagerImpl registers a policy whose on-chain/config bytes cannot be unmarshalled into cb.SignaturePolicyEnvelope — wrong protobuf type, truncated data, or non-proto bytes stored under the policy key.","commonSituations":"A policy bytes blob written as implicit-meta or another format but registered with the signature-policy provider; corrupt channel config block; mismatched proto registration after changing the pb.go packages in use.","solutions":["Verify the bytes are a proto.Marshal output of cb.SignaturePolicyEnvelope, not another policy type (e.g. ImplicitMetaPolicy)","Inspect the raw bytes with proto.UnmarshalText or a decoder to identify the actual message type","Regenerate/redistribute the channel configuration containing the policy"],"exampleFix":"// before\nprovider.NewPolicy([]byte(\" Administrators: majority\")) // meta-syntax, not a proto envelope\n// after\nenv := &cb.SignaturePolicyEnvelope{Version: 0, Rule: ..., Identities: ...}\nprovider.NewPolicy(protoutil.MarshalOrPanic(env))","handlingStrategy":"validation","validationCode":"probe := &cb.SignaturePolicyEnvelope{}\nif err := proto.Unmarshal(data, probe); err != nil {\n    return fmt.Errorf(\"bytes are not a SignaturePolicyEnvelope: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"policy, _, err := provider.NewPolicy(data)\nif err != nil && strings.Contains(err.Error(), \"Error unmarshalling to SignaturePolicy\") {\n    log.Printf(\"stored policy bytes are not a SignaturePolicyEnvelope, raw=%x\", data)\n}","preventionTips":["Store only proto.Marshal output of the exact message type under each policy key","Include a type tag/metadata alongside stored policy bytes","Never hand-edit serialized policy blobs"],"tags":["protobuf","policy","unmarshal"],"backgroundTag":"proto-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"}