Skip to content

Commit

Permalink
Improve exception handling when application fails to start
Browse files Browse the repository at this point in the history
Prevent the usage of the logger when the application has not started
regardless of the cause since it's most likely not configured yet.

Closes quarkusio#42084
  • Loading branch information
zakkak committed Aug 1, 2024
1 parent 7f35270 commit 28747ca
Showing 1 changed file with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.logging.Handler;
import java.util.stream.Collectors;

import io.quarkus.runtime.util.StringUtil;
import jakarta.enterprise.context.spi.CreationalContext;
import jakarta.enterprise.inject.Any;
import jakarta.enterprise.inject.spi.Bean;
Expand All @@ -24,11 +25,8 @@

import io.quarkus.bootstrap.logging.InitialConfigurator;
import io.quarkus.bootstrap.runner.RunnerClassLoader;
import io.quarkus.runtime.configuration.ConfigurationException;
import io.quarkus.runtime.graal.DiagnosticPrinter;
import io.quarkus.runtime.util.ExceptionUtil;
import io.quarkus.runtime.util.StringUtil;
import io.smallrye.config.ConfigValidationException;
import sun.misc.Signal;
import sun.misc.SignalHandler;

Expand Down Expand Up @@ -188,11 +186,12 @@ public static void run(Application application, Class<? extends QuarkusApplicati
}
applicationLogger.warn("You can try to kill it with 'kill -9 <pid>'.");
}
} else if (rootCause instanceof ConfigurationException || rootCause instanceof ConfigValidationException) {
System.err.println(rootCause.getMessage());
} else if (rootCause instanceof PreventFurtherStepsException
&& !StringUtil.isNullOrEmpty(rootCause.getMessage())) {
System.err.println(rootCause.getMessage());
} else if (!currentApplication.isStarted()) {
System.err.println("Failed to start application");
e.printStackTrace();
} else {
applicationLogger.errorv(e, "Failed to start application");
ensureConsoleLogsDrained();
Expand Down

0 comments on commit 28747ca

Please sign in to comment.