Skip to content

Commit

Permalink
revert dirty class assertion, change approach on handling Configurati…
Browse files Browse the repository at this point in the history
…onException in build step
  • Loading branch information
MaciejDromin committed Dec 18, 2023
1 parent 3fc3ad0 commit a289aeb
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
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;
Expand All @@ -89,7 +88,6 @@
import io.quarkus.runtime.annotations.QuarkusMain;
import io.quarkus.runtime.appcds.AppCDSUtil;
import io.quarkus.runtime.configuration.ConfigUtils;
import io.quarkus.runtime.configuration.ConfigurationException;
import io.quarkus.runtime.configuration.ProfileManager;
import io.quarkus.runtime.util.StepTiming;

Expand Down Expand Up @@ -330,14 +328,7 @@ void build(List<StaticBytecodeRecorderBuildItem> staticInitTasks,
}

cb.invokeVirtualMethod(ofMethod(StartupContext.class, "close", void.class), startupContext);

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());
cb.throwException(RuntimeException.class, "Failed to start quarkus", cb.getCaughtException());
mv.returnValue(null);

// Application class: stop method
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,11 @@ public static void run(Application application, Class<? extends QuarkusApplicati
}
}
} catch (Exception e) {
// Here it is trying to get rootCause in which when ConfigurationException is thrown
// is ConfigValidationException from io.smallrye.config
Throwable rootCause = e instanceof ConfigurationException ? e : ExceptionUtil.getRootCause(e);
// Here if ConfigurationException is one step up on the chain we want to return it
// because it wraps ConfigValidationException from io.smallrye.config
Throwable rootCause = e.getCause() instanceof ConfigurationException
? e.getCause()
: ExceptionUtil.getRootCause(e);
if (exitCodeHandler == null) {
Logger applicationLogger = Logger.getLogger(Application.class);
if (rootCause instanceof QuarkusBindException) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.quarkus.grpc.auth;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.Assertions;
Expand All @@ -20,7 +19,7 @@ public class SecurityEventsValidationFailureTest {
.addClass(SecurityEventObserver.class)
.addPackage(SecuredService.class.getPackage()))
.assertException(throwable -> {
assertEquals(throwable.getClass().getName(), ConfigurationException.class.getName());
assertTrue(throwable instanceof ConfigurationException);
assertTrue(throwable.getMessage().contains("quarkus.security.events.enabled"));
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class ConfigEnabledFalseAndActiveTrueTest {
.overrideConfigKey("quarkus.hibernate-orm.enabled", "false")
.overrideConfigKey("quarkus.hibernate-orm.active", "true")
.assertException(throwable -> assertThat(throwable)
.matches(t -> t.getClass().getName().equals(ConfigurationException.class.getName()))
.isInstanceOf(ConfigurationException.class)
.hasMessageContaining(
"Hibernate ORM activated explicitly for persistence unit '<default>', but the Hibernate ORM extension was disabled at build time",
"If you want Hibernate ORM to be active at runtime, you must set 'quarkus.hibernate-orm.enabled' to 'true' at build time",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class TransactionJdbcObjectStoreValidationFailureTest {
.setForcedDependencies(List.of(Dependency.of("io.quarkus", "quarkus-jdbc-h2", Version.getVersion())))
.assertException(t -> {
Throwable rootCause = ExceptionUtil.getRootCause(t);
if (rootCause.getClass().getName().equals(ConfigurationException.class.getName())) {
if (rootCause instanceof ConfigurationException) {
assertTrue(rootCause.getMessage().contains(
"The Narayana JTA extension is configured to use the datasource 'test' but that datasource is not configured."));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class OpaqueTokenVerificationWithUserInfoValidationTest {
Throwable e = t;
ConfigurationException te = null;
while (e != null) {
if (e.getClass().getName().equals(ConfigurationException.class.getName())) {
if (e instanceof ConfigurationException) {
te = (ConfigurationException) e;
break;
}
Expand Down

0 comments on commit a289aeb

Please sign in to comment.