Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.

Commit 4498a41

Browse files
author
Pavan Kappara
committed
[FAB-8943] error codes for entity matchers
Error codes for signature validation and entity matchers Change-Id: Id64e3c88aadd1bbb26aadfdc984bba23688264f5 Signed-off-by: Pavan Kappara <pavan.kappara@securekey.com>
1 parent 0cc07c8 commit 4498a41

File tree

5 files changed

+44
-19
lines changed

5 files changed

+44
-19
lines changed

pkg/client/channel/invoke/signature_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ SPDX-License-Identifier: Apache-2.0
77
package invoke
88

99
import (
10-
"errors"
1110
"strings"
1211
"testing"
1312

1413
txnmocks "github.com/hyperledger/fabric-sdk-go/pkg/client/common/mocks"
1514
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
1615
fcmocks "github.com/hyperledger/fabric-sdk-go/pkg/fab/mocks"
16+
"github.com/hyperledger/fabric-sdk-go/pkg/util/errors/status"
1717
"github.com/stretchr/testify/assert"
1818
)
1919

@@ -33,7 +33,7 @@ func TestSignatureValidationHandlerSuccess(t *testing.T) {
3333
}
3434

3535
func TestSignatureValidationCreatorValidateError(t *testing.T) {
36-
validateErr := errors.New("ValidateErr")
36+
validateErr := status.New(status.EndorserClientStatus, status.SignatureVerificationFailed.ToInt32(), "", nil)
3737
// Sample request
3838
request := Request{ChaincodeID: "testCC", Fcn: "invoke", Args: [][]byte{[]byte("query"), []byte("b")}}
3939
requestContext := prepareRequestContext(request, Opts{}, t)
@@ -47,7 +47,7 @@ func TestSignatureValidationCreatorValidateError(t *testing.T) {
4747
}
4848

4949
func TestSignatureValidationCreatorVerifyError(t *testing.T) {
50-
verifyErr := errors.New("Verify")
50+
verifyErr := status.New(status.EndorserClientStatus, status.SignatureVerificationFailed.ToInt32(), "", nil)
5151

5252
// Sample request
5353
request := Request{ChaincodeID: "testCC", Fcn: "invoke", Args: [][]byte{[]byte("query"), []byte("b")}}

pkg/client/common/verifier/signature.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ func (v *Signature) Verify(response *fab.TransactionProposalResponse) error {
3232
res := response.ProposalResponse
3333

3434
if res.GetEndorsement() == nil {
35-
return errors.Errorf("Missing endorsement in proposal response")
35+
return errors.WithStack(status.New(status.EndorserClientStatus, status.MissingEndorsement.ToInt32(), "missing endorsement in proposal response", nil))
3636
}
3737
creatorID := res.GetEndorsement().Endorser
3838

3939
err := v.Membership.Validate(creatorID)
4040
if err != nil {
41-
return errors.WithMessage(err, "The creator certificate is not valid")
41+
return errors.WithStack(status.New(status.EndorserClientStatus, status.SignatureVerificationFailed.ToInt32(), "the creator certificate is not valid", []interface{}{err.Error()}))
4242
}
4343

4444
// check the signature against the endorser and payload hash
@@ -47,7 +47,7 @@ func (v *Signature) Verify(response *fab.TransactionProposalResponse) error {
4747
// validate the signature
4848
err = v.Membership.Verify(creatorID, digest, res.GetEndorsement().Signature)
4949
if err != nil {
50-
return errors.WithMessage(err, "The creator's signature over the proposal is not valid")
50+
return errors.WithStack(status.New(status.EndorserClientStatus, status.SignatureVerificationFailed.ToInt32(), "the creator's signature over the proposal is not valid", []interface{}{err.Error()}))
5151
}
5252

5353
return nil

pkg/core/config/config.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/core"
2929
"github.com/hyperledger/fabric-sdk-go/pkg/core/config/cryptoutil"
3030
"github.com/hyperledger/fabric-sdk-go/pkg/core/config/endpoint"
31+
"github.com/hyperledger/fabric-sdk-go/pkg/util/errors/status"
3132
"github.com/pkg/errors"
3233

3334
"regexp"
@@ -494,8 +495,8 @@ func (c *Config) tryMatchingCAConfig(caName string) (*core.CAConfig, string, err
494495
return &caConfig, certAuthorityMatchConfig.MappedHost, nil
495496
}
496497
}
497-
return nil, "", errors.New("no matching certAuthority config found")
498498

499+
return nil, "", errors.WithStack(status.New(status.ClientStatus, status.NoMatchingCertificateAuthorityEntity.ToInt32(), "no matching certAuthority config found", nil))
499500
}
500501

501502
// CAClientCertPem Read configuration option for the fabric CA client cert pem embedded in the client config
@@ -870,7 +871,8 @@ func (c *Config) tryMatchingPeerConfig(peerName string) (*core.PeerConfig, error
870871
return &peerConfig, nil
871872
}
872873
}
873-
return nil, errors.New("no matching peer config found")
874+
875+
return nil, errors.WithStack(status.New(status.ClientStatus, status.NoMatchingPeerEntity.ToInt32(), "no matching peer config found", nil))
874876
}
875877

876878
func (c *Config) tryMatchingOrdererConfig(ordererName string) (*core.OrdererConfig, error) {
@@ -952,7 +954,8 @@ func (c *Config) tryMatchingOrdererConfig(ordererName string) (*core.OrdererConf
952954
return &ordererConfig, nil
953955
}
954956
}
955-
return nil, errors.New("no matching orderer config found")
957+
958+
return nil, errors.WithStack(status.New(status.ClientStatus, status.NoMatchingOrdererEntity.ToInt32(), "no matching orderer config found", nil))
956959
}
957960

958961
func copyPropertiesMap(origMap map[string]interface{}) map[string]interface{} {
@@ -989,7 +992,8 @@ func (c *Config) findMatchingPeer(peerName string) (string, error) {
989992
return peerMatchConfig.MappedHost, nil
990993
}
991994
}
992-
return "", errors.New("no matching peers found")
995+
996+
return "", errors.WithStack(status.New(status.ClientStatus, status.NoMatchingPeerEntity.ToInt32(), "no matching peer config found", nil))
993997
}
994998

995999
func (c *Config) compileMatchers() error {

pkg/fab/channel/responsevalidator.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ package channel
99
import (
1010
"github.com/golang/protobuf/proto"
1111
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
12+
"github.com/hyperledger/fabric-sdk-go/pkg/util/errors/status"
1213
"github.com/pkg/errors"
1314
)
1415

@@ -53,7 +54,7 @@ func (tprv *TransactionProposalResponseVerifier) Match(transactionProposalRespon
5354
}
5455

5556
if !proto.Equal(block.Data, b.Data) {
56-
return errors.New("payloads for config block do not match")
57+
return errors.WithStack(status.New(status.EndorserClientStatus, status.EndorsementMismatch.ToInt32(), "payloads for config block do not match", nil))
5758
}
5859
}
5960

pkg/util/errors/status/codes.go

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,38 @@ const (
4141

4242
// MultipleErrors multiple errors occurred
4343
MultipleErrors Code = 7
44+
45+
// SignatureVerificationFailed is when signature fails verification
46+
SignatureVerificationFailed Code = 8
47+
48+
// MissingEndorsement is if an endoresement is missing
49+
MissingEndorsement Code = 9
50+
51+
// NoMatchingCertificateAuthorityEntity is if entityMatchers are unable to find any matchingCertificateAuthority
52+
NoMatchingCertificateAuthorityEntity Code = 21
53+
54+
// NoMatchingPeerEntity is if entityMatchers are unable to find any matchingPeer
55+
NoMatchingPeerEntity Code = 22
56+
57+
// NoMatchingOrdererEntity is if entityMatchers are unable to find any matchingOrderer
58+
NoMatchingOrdererEntity Code = 23
4459
)
4560

4661
// CodeName maps the codes in this packages to human-readable strings
4762
var CodeName = map[int32]string{
48-
0: "OK",
49-
1: "UNKNOWN",
50-
2: "CONNECTION_FAILED",
51-
3: "ENDORSEMENT_MISMATCH",
52-
4: "EMPTY_CERT",
53-
5: "TIMEOUT",
54-
6: "NO_PEERS_FOUND",
55-
7: "MULTIPLE_ERRORS",
63+
0: "OK",
64+
1: "UNKNOWN",
65+
2: "CONNECTION_FAILED",
66+
3: "ENDORSEMENT_MISMATCH",
67+
4: "EMPTY_CERT",
68+
5: "TIMEOUT",
69+
6: "NO_PEERS_FOUND",
70+
7: "MULTIPLE_ERRORS",
71+
8: "SIGNATURE_VERIFICATION_FAILED",
72+
9: "MISSING_ENDORSEMENT",
73+
21: "NO_MATCHING_CERTIFICATE_AUTHORITY_ENTITY",
74+
22: "NO_MATCHING_PEER_ENTITY",
75+
23: "NO_MATCHING_ORDERER_ENTITY",
5676
}
5777

5878
// ToInt32 cast to int32

0 commit comments

Comments
 (0)