Need a way to find out from FlywayException which SQL command failed #548
Comments
Thanks for the report. I agree with you, this would make total sense from an API perspective. I'll look into it. |
Hi Axel, it seems to me the problem is with the e.toString() call instead of the use of e.getStackTrace() in applyMigration():
The stack trace is swallowed and that makes important information such as the line number of the exception disappear. Best regards, |
Hi there, Logging of the exception is not an issue, rather I would like to get the actual exception raised up to the top level FlywayException (wrapped by or included into it). Thanks, |
Hi! I have created a quick solution for the issue. Add this method to ExceptionUtils: /**
* Returns the StackTrace of this throwable as a string. Each lines are separated by a newline (\n) character.
*
* @param throwable
* @return String representation of the StackTrace
*/
public static String getStackTrace(Throwable throwable) {
StringBuilder sb = new StringBuilder(2000);
StackTraceElement[] stackTrace = throwable.getStackTrace();
boolean first = true;
for (StackTraceElement ste : stackTrace) {
if(!first) sb.append("\n\t at ");
sb.append(ste.toString());
first=false;
}
return sb.toString();
} and change DBMigrate#applyMigration (lines 264-266) to if (rootCause != null) {
LOG.error("Caused by " + ExceptionUtils.getStackTrace(rootCause));
} Best regards, |
Implementation of #548 feature request
This feature request partially duplicates #234 bug.
I would like to have ability to obtain some details regarding failed SQL statements from the generated FlywayException.
For example, the code:
produces exception like:
But I want to tell end user (in my case it is a system administrator) what exactly happened during the migration and give her ability to fix the situation and repeat the attempt.
The current implementation gives only one way to know about the errors -- the log file (tested with Oracle DB):
I would like to see an extension of FlywayException interface (or subclass e.g. FlywayMigrationException) that can give me a list of errors occurred during migration (or only the first error -- because Flyway does not apply subsequent migrations), so it can be processed by business logic.
The text was updated successfully, but these errors were encountered: