Skip to content

Commit

Permalink
Fix formatting of messages logged to logview and prevent NPE
Browse files Browse the repository at this point in the history
Reviewed By: dinhviethoa

fbshipit-source-id: 959e1f0
  • Loading branch information
Sergey Tyurin authored and facebook-github-bot committed Oct 3, 2017
1 parent 813975a commit 63c0508
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/com/facebook/buck/log/AbstractErrorLogRecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,22 @@ public ImmutableMap<String, String> getTraits() {
public String getMessage() {
Optional<String> initialErr = Optional.empty();
Optional<String> initialErrorMsg = Optional.empty();
Optional<String> errorMsg = Optional.empty();
Throwable throwable = getRecord().getThrown();
if (throwable != null) {
initialErr = Optional.ofNullable(getInitialCause(throwable).getClass().getName());
if (throwable.getMessage() != null) {
initialErrorMsg = Optional.ofNullable(getInitialCause(throwable).getLocalizedMessage());
}
}
errorMsg = Optional.ofNullable(getRecord().getMessage());

Optional<String> errorMsg;
String message = getRecord().getMessage();
Object[] parameters = getRecord().getParameters();
if (message != null && parameters != null) {
errorMsg = Optional.ofNullable(String.format(message, parameters));
} else {
errorMsg = Optional.ofNullable(message);
}
StringBuilder sb = new StringBuilder();
for (Optional<String> field : ImmutableList.of(initialErr, initialErrorMsg, errorMsg)) {
sb.append(field.orElse(""));
Expand Down

0 comments on commit 63c0508

Please sign in to comment.