Skip to content

Commit

Permalink
Merge "FABN-1333 improve error message"
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-coleman authored and Gerrit Code Review committed Oct 11, 2019
2 parents 5834c7d + 70ce950 commit 65e5a25
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
19 changes: 12 additions & 7 deletions fabric-network/src/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,22 @@ class Network {

let ledgerPeers;
if (discovery.enabled) {
ledgerPeers = this.gateway.getClient().getPeersForOrg();
const client = this.gateway.getClient();
ledgerPeers = client.getPeersForOrg();
if (ledgerPeers.length === 0) {
const msg = `No peers defined for MSP '${client.getMspid()}' to discover from`;
logger.error('_initializeInternalChannel: ' + msg);
throw new Error(msg);
}
} else {
ledgerPeers = this.channel.getPeers().filter((cPeer) => {
return cPeer.isInRole(FabricConstants.NetworkConfig.LEDGER_QUERY_ROLE);
});
}

if (ledgerPeers.length === 0) {
const msg = 'no suitable peers available to initialize from';
logger.error('_initializeInternalChannel: ' + msg);
throw new Error(msg);
if (ledgerPeers.length === 0) {
const msg = 'No peers defined in channel that have the ledger query role';
logger.error('_initializeInternalChannel: ' + msg);
throw new Error(msg);
}
}

let ledgerPeerIndex = 0;
Expand Down
13 changes: 11 additions & 2 deletions fabric-network/test/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,18 @@ describe('Network', () => {
mockPeer5.isInRole.withArgs(FABRIC_CONSTANTS.NetworkConfig.LEDGER_QUERY_ROLE).returns(false);
peerArray = [mockPeer1, mockPeer2, mockPeer3, mockPeer4, mockPeer5];
mockChannel.getPeers.returns(peerArray);
return network._initializeInternalChannel({discover: false})
.should.be.rejectedWith(/no suitable peers available to initialize from/);
return network._initializeInternalChannel({enabled:false, asLocalhost: true})
.should.be.rejectedWith(/No peers defined in channel that have the ledger query role/);
});

it('should fail if no peers defined for specified MSP', async () => {
network.initialized = false;
mockClient.getPeersForOrg.returns([]);
mockClient.getMspid.returns('myMSP');
return network._initializeInternalChannel({enabled:true, asLocalhost: true})
.should.be.rejectedWith(/No peers defined for MSP \'myMSP\' to discover from/);
});

});

describe('#initialize', () => {
Expand Down

0 comments on commit 65e5a25

Please sign in to comment.