Skip to content

Commit

Permalink
refactor: PreventFurtherStepsEx controls exitCode
Browse files Browse the repository at this point in the history
  • Loading branch information
iocanel committed Nov 17, 2022
1 parent a46d6e6 commit 3f8b51d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import io.quarkus.runtime.configuration.ConfigurationException;
import io.quarkus.runtime.configuration.ProfileManager;
import io.quarkus.runtime.graal.DiagnosticPrinter;
import io.quarkus.runtime.util.ExceptionUtil;
import sun.misc.Signal;
import sun.misc.SignalHandler;

Expand Down Expand Up @@ -155,11 +156,8 @@ public static void run(Application application, Class<? extends QuarkusApplicati
}
}
} catch (Exception e) {
Throwable rootCause = ExceptionUtil.getRootCause(e);
if (exitCodeHandler == null) {
Throwable rootCause = e;
while (rootCause.getCause() != null) {
rootCause = rootCause.getCause();
}
Logger applicationLogger = Logger.getLogger(Application.class);
if (rootCause instanceof QuarkusBindException) {
List<Integer> ports = ((QuarkusBindException) rootCause).getPorts();
Expand Down Expand Up @@ -205,7 +203,10 @@ public static void run(Application application, Class<? extends QuarkusApplicati
stateLock.unlock();
}
application.stop();
(exitCodeHandler == null ? defaultExitCodeHandler : exitCodeHandler).accept(1, e);
int exceptionExitCode = rootCause instanceof PreventFurtherStepsException
? ((PreventFurtherStepsException) rootCause).getExitCode()
: 1;
(exitCodeHandler == null ? defaultExitCodeHandler : exitCodeHandler).accept(exceptionExitCode, e);
return;
} finally {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,19 @@
* for example in AppCDS generation.
*/
public final class PreventFurtherStepsException extends RuntimeException {

private final int exitCode;

public PreventFurtherStepsException() {
this(1);
}

public PreventFurtherStepsException(int exitCode) {
super();
this.exitCode = exitCode;
}

public int getExitCode() {
return exitCode;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void doStartActions() {

for (FlywayContainer flywayContainer : FLYWAY_CONTAINERS) {
if (flywayContainer.isRunAndExit()) {
throw new PreventFurtherStepsException();
throw new PreventFurtherStepsException(0);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void doStartActions() {
LiquibaseFactory liquibaseFactory = liquibaseFactoryHandle.get();
var config = liquibaseFactory.getConfiguration();
if (config.runAndExit) {
throw new PreventFurtherStepsException();
throw new PreventFurtherStepsException(0);
}

}
Expand Down

0 comments on commit 3f8b51d

Please sign in to comment.