Skip to content

Commit

Permalink
Merge pull request #2017 from scireum/feature/SIRI-985-show-more-info…
Browse files Browse the repository at this point in the history
…rmation-wrapped-exceptions

Shows more information for wrapped exceptions
  • Loading branch information
bkositza authored Jul 2, 2024
2 parents 66b9edc + a63a1ad commit d7f6782
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/main/java/sirius/biz/protocol/Protocols.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ private String buildErrorMessages(Throwable throwable) {
// Therefore, the first element is skipped.
Throwables.getCausalChain(throwable).stream().skip(1).forEach(cause -> {
stringBuilder.append("\n").append("Caused by: ").append(cause.getClass().getName()).append(":").append("\n");
stringBuilder.append(truncateErrorMessage(cause.getMessage(), numberOfCharactersPerMessage)).append("\n\n");
stringBuilder.append(truncateErrorMessage(determineErrorMessage(cause), numberOfCharactersPerMessage)).append("\n\n");
});
} catch (IllegalArgumentException exception) {
// This happens if the causal chain has a circular reference.
Expand All @@ -167,6 +167,16 @@ private String buildErrorMessages(Throwable throwable) {
return stringBuilder.toString();
}

private String determineErrorMessage(Throwable throwable) {
if (Strings.isFilled(throwable.getMessage())) {
return throwable.getMessage();
}
if (Strings.areEqual(throwable.getClass().getName(), throwable.toString())) {
return "";
}
return throwable.toString();
}

private String truncateErrorMessage(String errorMessage, int length) {
int charsToPreserveFromStart = Math.max(0, length - NUMBER_OF_CHARS_TO_PRESERVE_AT_THE_END_OF_AN_ERROR_MESSAGE);
return Strings.truncateMiddle(errorMessage, charsToPreserveFromStart, NUMBER_OF_CHARS_TO_PRESERVE_AT_THE_END_OF_AN_ERROR_MESSAGE);
Expand Down

0 comments on commit d7f6782

Please sign in to comment.