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

Do not log stack trace if isExpected flag is true for CommandFailedException #5898

Merged
merged 1 commit into from
May 29, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,9 @@ protected int handleException(Throwable exception) {
//
Level level = determineLogLevel(exception);

Scope.getCurrentScope().getLog(getClass()).log(level, uiMessage, exception);
if (showExceptionInLog(exception)) {
Scope.getCurrentScope().getLog(getClass()).log(level, uiMessage, exception);
}

boolean printUsage = false;
try (final StringWriter suggestionWriter = new StringWriter();
Expand All @@ -264,7 +266,7 @@ protected int handleException(Throwable exception) {
|| exception instanceof CommandLineParsingException) {
System.err.println("Error parsing command line: " + uiMessage);
printUsage = true;
} else if (exception.getCause() != null && exception.getCause() instanceof CommandFailedException) {
} else if (exception.getCause() instanceof CommandFailedException) {
System.err.println(uiMessage);
} else {
System.err.println("\nUnexpected error running Liquibase: " + uiMessage);
Expand All @@ -286,7 +288,7 @@ protected int handleException(Throwable exception) {

suggestionsPrintWriter.flush();
final String suggestions = suggestionWriter.toString();
if (suggestions.length() > 0) {
if (!suggestions.isEmpty()) {
System.err.println();
System.err.println(suggestions);
}
Expand All @@ -303,6 +305,20 @@ protected int handleException(Throwable exception) {
return 1;
}

//
// Honor the expected flag on a CommandFailedException
//
private boolean showExceptionInLog(Throwable exception) {
Throwable t = exception;
while (t != null) {
if (t instanceof CommandFailedException && ((CommandFailedException) t).isExpected()) {
return false;
}
t = t.getCause();
}
return true;
}

//
// Look for a logLevel setting on any LiquibaseException
// and use that for the Level to pass to the logger.
Expand Down
Loading