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

Commit 6fac3aa

Browse files
committed
[FAB-8943] client status code
This change adjusts: the error for the peer filter to return NoPeersFound code. Change-Id: Id1eff408244e211d0f03b50743eb93c11794dd2b Signed-off-by: Troy Ronda <troy@troyronda.com>
1 parent f3453ac commit 6fac3aa

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

pkg/client/ledger/ledger.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ func (c *Client) calculateTargets(opts requestOptions) ([]fab.Peer, error) {
357357
}
358358

359359
if len(targets) == 0 {
360-
return nil, errors.New("No targets available")
360+
return nil, errors.WithStack(status.New(status.ClientStatus, status.NoPeersFound.ToInt32(), "no targets available", nil))
361361
}
362362

363363
if len(targets) < opts.MinTargets {

pkg/client/resmgmt/resmgmt.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ func (rc *Client) JoinChannel(channelID string, options ...RequestOption) error
184184
}
185185

186186
if len(targets) == 0 {
187-
return errors.New("No targets available")
187+
return errors.WithStack(status.New(status.ClientStatus, status.NoPeersFound.ToInt32(), "no targets available", nil))
188188
}
189189

190190
orderer, err := rc.requestOrderer(&opts, channelID)
@@ -334,7 +334,7 @@ func (rc *Client) InstallCC(req InstallCCRequest, options ...RequestOption) ([]I
334334
}
335335

336336
if len(targets) == 0 {
337-
return nil, errors.New("No targets available for install cc")
337+
return nil, errors.WithStack(status.New(status.ClientStatus, status.NoPeersFound.ToInt32(), "no targets available", nil))
338338
}
339339

340340
responses := make([]InstallCCResponse, 0)
@@ -537,7 +537,7 @@ func (rc *Client) sendCCProposal(reqCtx reqContext.Context, ccProposalType chain
537537
}
538538

539539
if len(targets) == 0 {
540-
return errors.New("No targets available for cc proposal")
540+
return errors.WithStack(status.New(status.ClientStatus, status.NoPeersFound.ToInt32(), "no targets available", nil))
541541
}
542542

543543
// Get transactor on the channel to create and send the deploy proposal

pkg/client/resmgmt/resmgmt_test.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"github.com/hyperledger/fabric-sdk-go/pkg/fab/resource/api"
3333
"github.com/hyperledger/fabric-sdk-go/pkg/fabsdk/provider/fabpvdr"
3434
mspmocks "github.com/hyperledger/fabric-sdk-go/pkg/msp/mocks"
35+
"github.com/hyperledger/fabric-sdk-go/pkg/util/errors/status"
3536
"github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/common/cauthdsl"
3637
"github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/common"
3738
pb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/peer"
@@ -176,10 +177,11 @@ func TestJoinChannelRequiredParameters(t *testing.T) {
176177

177178
// Test missing default targets
178179
err = rc.JoinChannel("mychannel")
179-
if err == nil || !strings.Contains(err.Error(), "No targets available") {
180-
t.Fatalf("InstallCC should have failed with no default targets error")
181-
}
182180

181+
assert.NotNil(t, err, "error should have been returned")
182+
s, ok := status.FromError(err)
183+
assert.True(t, ok, "status code should be available")
184+
assert.Equal(t, status.NoPeersFound.ToInt32(), s.Code, "code should be no peers found")
183185
}
184186

185187
func TestJoinChannelWithOptsRequiredParameters(t *testing.T) {
@@ -226,9 +228,10 @@ func TestJoinChannelWithOptsRequiredParameters(t *testing.T) {
226228

227229
// Test filter only (filter has no match)
228230
err = rc.JoinChannel("mychannel", WithTargetFilter(&mspFilter{mspID: "MSPID"}))
229-
if err == nil || !strings.Contains(err.Error(), "No targets available") {
230-
t.Fatalf("InstallCC should have failed with no targets error")
231-
}
231+
assert.NotNil(t, err, "error should have been returned")
232+
s, ok := status.FromError(err)
233+
assert.True(t, ok, "status code should be available")
234+
assert.Equal(t, status.NoPeersFound.ToInt32(), s.Code, "code should be no peers found")
232235

233236
//Some cleanup before further test
234237
orderer = fcmocks.NewMockOrderer("", nil)

0 commit comments

Comments
 (0)