Skip to content

Commit 600769d

Browse files
committed
Wrapping exceptions at startup with StartupException.
1 parent 727acde commit 600769d

3 files changed

Lines changed: 27 additions & 4 deletions

File tree

jooby/src/main/java/io/jooby/Jooby.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import com.typesafe.config.Config;
99
import io.jooby.exception.RegistryException;
10+
import io.jooby.exception.StartupException;
1011
import io.jooby.internal.LocaleUtils;
1112
import io.jooby.internal.RouterImpl;
1213
import org.slf4j.Logger;
@@ -724,7 +725,7 @@ public Jooby errorCode(@Nonnull Class<? extends Throwable> type,
724725
log.info("Server stop resulted in exception", stopx);
725726
}
726727
// rethrow
727-
throw SneakyThrows.propagate(x);
728+
throw new StartupException("Application startup resulted in exception", x);
728729
}
729730
}
730731

@@ -1047,7 +1048,7 @@ public static Jooby createApp(@Nonnull String[] args, @Nonnull ExecutionMode exe
10471048
LoggerFactory.getLogger(Jooby.class)
10481049
.error("Application initialization resulted in exception", t);
10491050

1050-
throw t;
1051+
throw new StartupException("Application initialization resulted in exception", t);
10511052
}
10521053

10531054
if (app.mode == null) {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package io.jooby.exception;
2+
3+
/**
4+
* Thrown when Jooby was unable to initialize and start
5+
* an application up.
6+
*/
7+
public class StartupException extends RuntimeException {
8+
9+
/**
10+
* Creates a new instance of this class with the specified message and cause.
11+
*
12+
* @param message The message
13+
* @param cause The cause
14+
*/
15+
public StartupException(String message, Throwable cause) {
16+
super(message, cause);
17+
}
18+
}

tests/src/test/java/io/jooby/Issue2107.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
import ch.qos.logback.classic.Logger;
55
import ch.qos.logback.classic.spi.ILoggingEvent;
66
import ch.qos.logback.core.read.ListAppender;
7+
import io.jooby.exception.StartupException;
78
import org.junit.jupiter.api.Test;
89
import org.slf4j.LoggerFactory;
910

1011
import static org.junit.jupiter.api.Assertions.assertEquals;
12+
import static org.junit.jupiter.api.Assertions.assertNotNull;
1113
import static org.junit.jupiter.api.Assertions.assertThrows;
1214

1315
public class Issue2107 {
@@ -19,8 +21,10 @@ public void appInitExceptionLogging() {
1921
appender.start();
2022
log.addAppender(appender);
2123

22-
Throwable t = assertThrows(RuntimeException.class, () -> Jooby.runApp(new String[0], App::new));
23-
assertEquals("meh", t.getMessage());
24+
Throwable t = assertThrows(StartupException.class, () -> Jooby.runApp(new String[0], App::new));
25+
assertEquals("Application initialization resulted in exception", t.getMessage());
26+
assertNotNull(t.getCause());
27+
assertEquals("meh", t.getCause().getMessage());
2428
assertEquals(1, appender.list.size());
2529

2630
final ILoggingEvent ev = appender.list.get(0);

0 commit comments

Comments
 (0)