diff --git a/core/deployment/src/main/java/io/quarkus/deployment/steps/MainClassBuildStep.java b/core/deployment/src/main/java/io/quarkus/deployment/steps/MainClassBuildStep.java index 2fef4a855d22e7..421f1e191f1532 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/steps/MainClassBuildStep.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/steps/MainClassBuildStep.java @@ -71,6 +71,7 @@ import io.quarkus.gizmo.ClassTransformer; import io.quarkus.gizmo.FieldCreator; import io.quarkus.gizmo.FieldDescriptor; +import io.quarkus.gizmo.IfThenElse; import io.quarkus.gizmo.MethodCreator; import io.quarkus.gizmo.MethodDescriptor; import io.quarkus.gizmo.ResultHandle; @@ -307,26 +308,36 @@ void build(List staticInitTasks, CatchBlockCreator preventFurtherStepsBlock = tryBlock.addCatch(PreventFurtherStepsException.class); preventFurtherStepsBlock.invokeVirtualMethod(ofMethod(StartupContext.class, "close", void.class), startupContext); - CatchBlockCreator catchConfigurationException = tryBlock.addCatch(ConfigurationException.class); - - // Handle Configuration Exception thrown at startup - handleThrownException(launchMode, catchConfigurationException); - - catchConfigurationException.invokeStaticMethod(ofMethod(ApplicationStateNotification.class, - "notifyStartupFailed", void.class, Throwable.class), - catchConfigurationException.getCaughtException()); - catchConfigurationException.invokeVirtualMethod(ofMethod(StartupContext.class, - "close", void.class), startupContext); - catchConfigurationException.throwException(catchConfigurationException.getCaughtException()); - mv.returnValue(null); - cb = tryBlock.addCatch(Throwable.class); - // Handle any exception that may be thrown at startup - handleThrownException(launchMode, cb); + // an exception was thrown before logging was actually setup, we simply dump everything to the console + // we don't do this for dev mode, as on startup failure dev mode sets up its own logging + if (launchMode.getLaunchMode() != LaunchMode.DEVELOPMENT) { + ResultHandle delayedHandler = cb + .readStaticField( + FieldDescriptor.of(InitialConfigurator.class, "DELAYED_HANDLER", QuarkusDelayedHandler.class)); + ResultHandle isActivated = cb.invokeVirtualMethod( + ofMethod(QuarkusDelayedHandler.class, "isActivated", boolean.class), + delayedHandler); + BytecodeCreator isActivatedFalse = cb.ifNonZero(isActivated).falseBranch(); + ResultHandle handlersArray = isActivatedFalse.newArray(Handler.class, 1); + isActivatedFalse.writeArrayValue(handlersArray, 0, + isActivatedFalse.newInstance(ofConstructor(ConsoleHandler.class))); + isActivatedFalse.invokeVirtualMethod( + ofMethod(QuarkusDelayedHandler.class, "setHandlers", Handler[].class, Handler[].class), + delayedHandler, handlersArray); + isActivatedFalse.breakScope(); + } cb.invokeVirtualMethod(ofMethod(StartupContext.class, "close", void.class), startupContext); - cb.throwException(RuntimeException.class, "Failed to start quarkus", cb.getCaughtException()); + + ResultHandle caughtException = cb.getCaughtException(); + + IfThenElse ifThenElse = cb.ifThenElse(cb.instanceOf(caughtException, ConfigurationException.class)); + BytecodeCreator ifThen = ifThenElse.then(); + ifThen.throwException(caughtException); + BytecodeCreator elseThen = ifThenElse.elseThen(); + elseThen.throwException(RuntimeException.class, "Failed to start quarkus", cb.getCaughtException()); mv.returnValue(null); // Application class: stop method @@ -346,27 +357,6 @@ void build(List staticInitTasks, file.close(); } - // an exception was thrown before logging was actually setup, we simply dump everything to the console - // we don't do this for dev mode, as on startup failure dev mode sets up its own logging - private void handleThrownException(LaunchModeBuildItem launchMode, CatchBlockCreator cb) { - if (launchMode.getLaunchMode() != LaunchMode.DEVELOPMENT) { - ResultHandle delayedHandler = cb - .readStaticField( - FieldDescriptor.of(InitialConfigurator.class, "DELAYED_HANDLER", QuarkusDelayedHandler.class)); - ResultHandle isActivated = cb.invokeVirtualMethod( - ofMethod(QuarkusDelayedHandler.class, "isActivated", boolean.class), - delayedHandler); - BytecodeCreator isActivatedFalse = cb.ifNonZero(isActivated).falseBranch(); - ResultHandle handlersArray = isActivatedFalse.newArray(Handler.class, 1); - isActivatedFalse.writeArrayValue(handlersArray, 0, - isActivatedFalse.newInstance(ofConstructor(ConsoleHandler.class))); - isActivatedFalse.invokeVirtualMethod( - ofMethod(QuarkusDelayedHandler.class, "setHandlers", Handler[].class, Handler[].class), - delayedHandler, handlersArray); - isActivatedFalse.breakScope(); - } - } - @BuildStep public MainClassBuildItem mainClassBuildStep(BuildProducer generatedClass, BuildProducer transformedClass, diff --git a/core/deployment/src/main/java/io/quarkus/deployment/steps/RuntimeConfigSetupBuildStep.java b/core/deployment/src/main/java/io/quarkus/deployment/steps/RuntimeConfigSetupBuildStep.java index 46064d3c477a2a..ee549589ec1a16 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/steps/RuntimeConfigSetupBuildStep.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/steps/RuntimeConfigSetupBuildStep.java @@ -48,7 +48,7 @@ void setupRuntimeConfig( tryBlock.invokeStaticMethod(C_CREATE_RUN_TIME_CONFIG); tryBlock.returnValue(null); - CatchBlockCreator cb = tryBlock.addCatch(Throwable.class); + CatchBlockCreator cb = tryBlock.addCatch(RuntimeException.class); cb.throwException(ConfigurationException.class, "Failed to read configuration properties", cb.getCaughtException()); } diff --git a/core/runtime/src/main/java/io/quarkus/runtime/ApplicationLifecycleManager.java b/core/runtime/src/main/java/io/quarkus/runtime/ApplicationLifecycleManager.java index 47cac2e7ba40a4..8276aacfca38bc 100644 --- a/core/runtime/src/main/java/io/quarkus/runtime/ApplicationLifecycleManager.java +++ b/core/runtime/src/main/java/io/quarkus/runtime/ApplicationLifecycleManager.java @@ -190,8 +190,8 @@ public static void run(Application application, Class'."); } } else if (rootCause instanceof ConfigurationException) { - applicationLogger.errorv(e, rootCause.getMessage()); - ensureConsoleLogsDrained(); + System.err.println(rootCause.getMessage()); + e.printStackTrace(); } else if (rootCause instanceof PreventFurtherStepsException && !StringUtil.isNullOrEmpty(rootCause.getMessage())) { System.err.println(rootCause.getMessage());