Skip to content

Commit

Permalink
FAB-5039 provide failure reason.
Browse files Browse the repository at this point in the history
Change-Id: Ib450f2d6944cdea0315cfaad0a882777fe3c9599
Signed-off-by: rickr <cr22rc@gmail.com>
  • Loading branch information
cr22rc committed Aug 15, 2017
1 parent 8eca761 commit 6ac15e6
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 7 deletions.
5 changes: 5 additions & 0 deletions checkstyle-config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@
<property name="option" value="bottom"/>
</module>

<!--<module name="MethodLength">-->
<!--<property name="max" value="250"/>-->
<!--</module>-->


<!-- Checks for Size Violations. -->
<!-- See http://checkstyle.sf.net/config_sizes.html -->
<module name="MethodLength"/>
Expand Down
66 changes: 59 additions & 7 deletions src/main/java/org/hyperledger/fabric/sdk/Channel.java
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,14 @@ private void sendUpdateChannel(byte[] configupdate, byte[][] signers, Orderer or

if (duration > CHANNEL_CONFIG_WAIT_TIME) {
//waited long enough .. throw an exception
throw new TransactionException(format("Channel %s update error timed out after %d ms. Status value %d. Status %s", name,
duration, statusCode, trxResult.getStatus().name()));
String info = trxResult.getInfo();
if (null == info) {
info = "";

}

throw new TransactionException(format("Channel %s update error timed out after %d ms. Status value %d. Status %s. %s", name,
duration, statusCode, trxResult.getStatus().name(), info));
}

try {
Expand All @@ -375,8 +381,15 @@ private void sendUpdateChannel(byte[] configupdate, byte[][] signers, Orderer or

} else if (200 != statusCode) {
// Can't retry.
throw new TransactionException(format("New channel %s error. StatusValue %d. Status %s", name,
statusCode, "" + trxResult.getStatus()));

String info = trxResult.getInfo();
if (null == info) {
info = "";

}

throw new TransactionException(format("New channel %s error. StatusValue %d. Status %s. %s", name,
statusCode, "" + trxResult.getStatus(), info));
}

} while (200 != statusCode); // try again
Expand Down Expand Up @@ -2378,7 +2391,6 @@ public CompletableFuture<TransactionEvent> sendTransaction(Collection<ProposalRe
if (null != diagnosticFileDumper) {
logger.trace(format("Sending to channel %s, orderer: %s, transaction: %s", name, orderer.getName(),
diagnosticFileDumper.createDiagnosticProtobufFile(transactionEnvelope.toByteArray())));

}

resp = orderer.sendTransaction(transactionEnvelope);
Expand All @@ -2391,7 +2403,26 @@ public CompletableFuture<TransactionEvent> sendTransaction(Collection<ProposalRe
} catch (Exception e) {
String emsg = format("Channel %s unsuccessful sendTransaction to orderer", name);
if (resp != null) {
emsg = format("Channel %s unsuccessful sendTransaction to orderer. Status %s", name, resp.getStatus());

StringBuilder respdata = new StringBuilder(400);

Status status = resp.getStatus();
if (null != status) {
respdata.append(status.name());
respdata.append("-");
respdata.append(status.getNumber());
}

String info = resp.getInfo();
if (null != info && !info.isEmpty()) {
if (respdata.length() > 0) {
respdata.append(", ");
}

respdata.append("Additional information: ").append(info);

}
emsg = format("Channel %s unsuccessful sendTransaction to orderer. %s", name, respdata.toString());
}

logger.error(emsg, e);
Expand All @@ -2404,7 +2435,28 @@ public CompletableFuture<TransactionEvent> sendTransaction(Collection<ProposalRe
logger.debug(format("Channel %s successful sent to Orderer transaction id: %s", name, proposalTransactionID));
return sret;
} else {
String emsg = format("Channel %s failed to place transaction %s on Orderer. Cause: UNSUCCESSFUL", name, proposalTransactionID);
StringBuilder respdata = new StringBuilder(400);
if (resp != null) {
Status status = resp.getStatus();
if (null != status) {
respdata.append(status.name());
respdata.append("-");
respdata.append(status.getNumber());
}

String info = resp.getInfo();
if (null != info && !info.isEmpty()) {
if (respdata.length() > 0) {
respdata.append(", ");
}

respdata.append("Additional information: ").append(info);

}

}
String emsg = format("Channel %s failed to place transaction %s on Orderer. Cause: UNSUCCESSFUL. %s",
name, proposalTransactionID, respdata.toString());
CompletableFuture<TransactionEvent> ret = new CompletableFuture<>();
ret.completeExceptionally(new Exception(emsg));
return ret;
Expand Down

0 comments on commit 6ac15e6

Please sign in to comment.