hyperledger/fabric · error
nil policy field
Error message
nil policy field
What it means
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.
Source
Thrown at common/cauthdsl/policy.go:112
}
// EvaluateIdentities takes an array of identities and evaluates whether
// they satisfy the policy
func (p *policy) EvaluateIdentities(identities []msp.Identity) error {
if p == nil {
return fmt.Errorf("No such policy")
}
ok := p.evaluator(identities, make([]bool, len(identities)))
if !ok {
return errors.New("signature set did not satisfy policy")
}
return nil
}
func (p *policy) Convert() (*cb.SignaturePolicyEnvelope, error) {
if p.signaturePolicyEnvelope == nil {
return nil, errors.New("nil policy field")
}
return p.signaturePolicyEnvelope, nil
}
View on GitHub (pinned to 2736b63f8f)
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
Example fix
// before
env, err := p.Convert() // p.signaturePolicyEnvelope == nil
// after
if p.signaturePolicyEnvelope == nil {
return nil, errors.New("policy has no envelope; reconstruct it from the rule")
}
env, err := p.Convert() Defensive patterns
Strategy: try-catch
Validate before calling
if p == nil || p.signaturePolicyEnvelope == nil {
return nil, errors.New("policy carries no envelope to convert")
} Type guard
func convertible(p *policy) bool { return p != nil && p.signaturePolicyEnvelope != nil } Try / catch
env, err := p.Convert()
if err != nil {
if err.Error() == "nil policy field" {
return nil, errors.New("this policy was constructed without an envelope")
}
return nil, err
} Prevention
- Prefer constructing policies through paths that retain the envelope
- Don't strip the envelope when wrapping compiled evaluators
- Document which policy constructors support Convert
When it happens
Trigger: 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).
Common situations: Framework code that round-trips policies to inspect or rewrite their envelopes encountering a policy constructed programmatically from an already-compiled closure.
Related errors
- no such policy
- No such policy
- error converting policy with reference '%s' on channel '%s'
- Invalid signed proposal during channelless check policy with
- Empty policy element
AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04).
Data as JSON: /api/errors/4b7c0508fe9539e1.
Report an issue: GitHub.