Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shows more information for wrapped exceptions #2017

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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