Skip to content

Commit

Permalink
MidPointSpringApplication: fatal exception is now reported to stderr
Browse files Browse the repository at this point in the history
Previously nothing was written, program silently finished and only
log showed more. Now the error is reported shortly to stderr as well.
  • Loading branch information
virgo47 committed Apr 19, 2022
1 parent 81ae316 commit fe6de37
Showing 1 changed file with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import com.evolveum.midpoint.common.configuration.api.MidpointConfiguration;
import com.evolveum.midpoint.gui.impl.factory.panel.TextAreaPanelFactory;
import com.evolveum.midpoint.gui.impl.registry.GuiComponentRegistryImpl;
import com.evolveum.midpoint.schema.util.ExceptionUtil;
import com.evolveum.midpoint.task.api.TaskManager;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
Expand Down Expand Up @@ -113,7 +114,12 @@ public static void main(String[] args) {
System.exit(SpringApplication.exit(applicationContext, () -> 0));

} else {
applicationContext = configureApplication(new SpringApplicationBuilder()).run(args);
try {
applicationContext = configureApplication(new SpringApplicationBuilder()).run(args);
} catch (Throwable e) {
reportFatalErrorToStdErr(e);
throw e;
}

if (LOGGER.isDebugEnabled()) {
LOGGER.debug("PID:" + ManagementFactory.getRuntimeMXBean().getName() +
Expand All @@ -122,6 +128,19 @@ public static void main(String[] args) {
}
}

private static final int MAX_FATAL_ERROR_OUTPUT_LENGTH = 300;

private static void reportFatalErrorToStdErr(Throwable e) {
System.err.println("ERROR initializing midPoint: "
+ StringUtils.abbreviate(e.toString(), MAX_FATAL_ERROR_OUTPUT_LENGTH));
Throwable rootCause = ExceptionUtil.findRootCause(e);
if (rootCause != null && rootCause != e) {
System.err.println("ROOT cause: "
+ StringUtils.abbreviate(rootCause.toString(), MAX_FATAL_ERROR_OUTPUT_LENGTH));
}
System.err.println("See midpoint.log for more details.");
}

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return configureApplication(application);
Expand Down

0 comments on commit fe6de37

Please sign in to comment.