Skip to content

Commit

Permalink
ninja better error message if DB schema version doesn't match and nin…
Browse files Browse the repository at this point in the history
…ja exits with error

(cherry picked from commit 68c18a4)
  • Loading branch information
1azyman committed Oct 10, 2023
1 parent e6cec7f commit 91649e4
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tools/ninja/src/main/java/com/evolveum/midpoint/ninja/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import com.evolveum.midpoint.ninja.util.InputParameterException;
import com.evolveum.midpoint.ninja.util.NinjaUtils;

import com.evolveum.midpoint.util.exception.SystemException;

import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -177,8 +179,25 @@ private void cleanupResources(BaseOptions opts, NinjaContext context) {
}
}

private Exception checkAndUnwrapException(Exception ex) {
Throwable throwable = ex;
while (throwable != null && !Objects.equals(throwable.getCause() , throwable)) {
throwable = throwable.getCause();
if (throwable instanceof SystemException) {
break;
}
}
if (throwable instanceof SystemException && throwable.getMessage().contains("repository context")) {
ex = (Exception) throwable;
}

return ex;
}

private void handleException(BaseOptions opts, Exception ex) {
if (!opts.isSilent()) {
ex = checkAndUnwrapException(ex);

err.println(ConsoleFormat.formatLogMessage(
LogLevel.ERROR, "Unexpected exception occurred (" + ex.getClass() + "), reason: " + ex.getMessage()));
}
Expand Down

0 comments on commit 91649e4

Please sign in to comment.