Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error msg by using the error pkg #4461

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 3 additions & 5 deletions common/cauthdsl/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ SPDX-License-Identifier: Apache-2.0
package cauthdsl

import (
"fmt"

"github.com/golang/protobuf/proto"
cb "github.com/hyperledger/fabric-protos-go/common"
"github.com/hyperledger/fabric/common/policies"
Expand All @@ -32,11 +30,11 @@ func NewPolicyProvider(deserializer msp.IdentityDeserializer) policies.Provider
func (pr *provider) NewPolicy(data []byte) (policies.Policy, proto.Message, error) {
sigPolicy := &cb.SignaturePolicyEnvelope{}
if err := proto.Unmarshal(data, sigPolicy); err != nil {
return nil, nil, fmt.Errorf("Error unmarshalling to SignaturePolicy: %s", err)
return nil, nil, errors.Wrap(err, "error unmarshalling to SignaturePolicy")
}

if sigPolicy.Version != 0 {
return nil, nil, fmt.Errorf("This evaluator only understands messages of version 0, but version was %d", sigPolicy.Version)
return nil, nil, errors.Errorf("this evaluator only understands messages of version 0, but version was %d", sigPolicy.Version)
}

compiled, err := compile(sigPolicy.Rule, sigPolicy.Identities)
Expand Down Expand Up @@ -97,7 +95,7 @@ func (p *policy) EvaluateSignedData(signatureSet []*protoutil.SignedData) error
// they satisfy the policy
func (p *policy) EvaluateIdentities(identities []msp.Identity) error {
if p == nil {
return fmt.Errorf("No such policy")
return errors.New("no such policy")
}

ok := p.evaluator(identities, make([]bool, len(identities)))
Expand Down
4 changes: 2 additions & 2 deletions common/cauthdsl/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,14 @@ func TestNewPolicyErrorCase(t *testing.T) {
pol1, msg1, err1 := provider.NewPolicy([]byte{0})
require.Nil(t, pol1)
require.Nil(t, msg1)
require.ErrorContains(t, err1, "Error unmarshalling to SignaturePolicy")
require.ErrorContains(t, err1, "error unmarshalling to SignaturePolicy")

sigPolicy2 := &cb.SignaturePolicyEnvelope{Version: -1}
data2 := marshalOrPanic(sigPolicy2)
pol2, msg2, err2 := provider.NewPolicy(data2)
require.Nil(t, pol2)
require.Nil(t, msg2)
require.EqualError(t, err2, "This evaluator only understands messages of version 0, but version was -1")
require.EqualError(t, err2, "this evaluator only understands messages of version 0, but version was -1")

pol3, msg3, err3 := provider.NewPolicy([]byte{})
require.Nil(t, pol3)
Expand Down