{"record":{"id":"4b7c0508fe9539e1","repo":"hyperledger/fabric","slug":"nil-policy-field","errorCode":null,"errorMessage":"nil policy field","messagePattern":"nil policy field","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"common/cauthdsl/policy.go","lineNumber":112,"sourceCode":"}\n\n// EvaluateIdentities takes an array of identities and evaluates whether\n// they satisfy the policy\nfunc (p *policy) EvaluateIdentities(identities []msp.Identity) error {\n\tif p == nil {\n\t\treturn fmt.Errorf(\"No such policy\")\n\t}\n\n\tok := p.evaluator(identities, make([]bool, len(identities)))\n\tif !ok {\n\t\treturn errors.New(\"signature set did not satisfy policy\")\n\t}\n\treturn nil\n}\n\nfunc (p *policy) Convert() (*cb.SignaturePolicyEnvelope, error) {\n\tif p.signaturePolicyEnvelope == nil {\n\t\treturn nil, errors.New(\"nil policy field\")\n\t}\n\n\treturn p.signaturePolicyEnvelope, nil\n}\n","sourceCodeStart":94,"sourceCodeEnd":117,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/common/cauthdsl/policy.go#L94-L117","documentation":"policy.Convert returns the stored *cb.SignaturePolicyEnvelope; policies created without one (signaturePolicyEnvelope left nil) cannot be converted, so this error is returned. Only used by consumers that need the original envelope back from a compiled policy.","triggerScenarios":"Calling (*policy).Convert on a policy whose signaturePolicyEnvelope field was never populated — i.e. the policy was built through a path that stores only the compiled evaluator (as in TestConverter).","commonSituations":"Framework code that round-trips policies to inspect or rewrite their envelopes encountering a policy constructed programmatically from an already-compiled closure.","solutions":["Only call Convert on policies created with their envelope attached, or nil-check inside the caller","Construct the policy via the path that stores signaturePolicyEnvelope","Return the envelope at policy-creation time instead of converting later"],"exampleFix":"// before\nenv, err := p.Convert() // p.signaturePolicyEnvelope == nil\n// after\nif p.signaturePolicyEnvelope == nil {\n    return nil, errors.New(\"policy has no envelope; reconstruct it from the rule\")\n}\nenv, err := p.Convert()","handlingStrategy":"try-catch","validationCode":"if p == nil || p.signaturePolicyEnvelope == nil {\n    return nil, errors.New(\"policy carries no envelope to convert\")\n}","typeGuard":"func convertible(p *policy) bool { return p != nil && p.signaturePolicyEnvelope != nil }","tryCatchPattern":"env, err := p.Convert()\nif err != nil {\n    if err.Error() == \"nil policy field\" {\n        return nil, errors.New(\"this policy was constructed without an envelope\")\n    }\n    return nil, err\n}","preventionTips":["Prefer constructing policies through paths that retain the envelope","Don't strip the envelope when wrapping compiled evaluators","Document which policy constructors support Convert"],"tags":["policy","nil-pointer","conversion"],"backgroundTag":"nil-policy-envelope","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"}