diff --git a/src/main/java/com/petshop/backend/DevStackApplication.java b/src/main/java/com/petshop/backend/DevStackApplication.java index 4fd47ffc..38846aaa 100644 --- a/src/main/java/com/petshop/backend/DevStackApplication.java +++ b/src/main/java/com/petshop/backend/DevStackApplication.java @@ -25,6 +25,7 @@ public class DevStackApplication { CountDownLatch shutdownLatch = new CountDownLatch(1); ScheduledExecutorService scheduler = null; AtomicBoolean shuttingDown = new AtomicBoolean(false); + RuntimeException startupFailure = null; try { validateJavaVersion(); @@ -42,6 +43,7 @@ public class DevStackApplication { scheduler = startDatabaseWatch(docker, context, shuttingDown); shutdownLatch.await(); } catch (RuntimeException ex) { + startupFailure = ex; throw new IllegalStateException(describeStartupFailure(ex), ex); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); @@ -54,7 +56,15 @@ public class DevStackApplication { context.close(); } if (!shuttingDown.get()) { - docker.stopDatabase(); + try { + docker.stopDatabase(); + } catch (RuntimeException stopFailure) { + if (startupFailure != null) { + System.err.println(stopFailure.getMessage()); + } else { + throw stopFailure; + } + } } } }