forked from StarOpenSource/Engine
Update/Fix engine init exception handling + errors
This commit is contained in:
parent
9d19dd8b57
commit
2f0bc19e7c
4 changed files with 29 additions and 15 deletions
|
@ -186,12 +186,8 @@ public final class Engine extends SubsystemClass {
|
||||||
* @since v1-alpha6
|
* @since v1-alpha6
|
||||||
*/
|
*/
|
||||||
private Engine() throws IllegalStateException {
|
private Engine() throws IllegalStateException {
|
||||||
if (instance == null)
|
|
||||||
instance = this;
|
|
||||||
else
|
|
||||||
return;
|
|
||||||
|
|
||||||
long initTime = Miscellaneous.measureExecutionTime(() -> {
|
long initTime = Miscellaneous.measureExecutionTime(() -> {
|
||||||
|
instance = this;
|
||||||
state = EngineState.EARLY_STARTUP;
|
state = EngineState.EARLY_STARTUP;
|
||||||
|
|
||||||
new EngineConfiguration();
|
new EngineConfiguration();
|
||||||
|
@ -217,7 +213,7 @@ public final class Engine extends SubsystemClass {
|
||||||
try {
|
try {
|
||||||
initializeSubsystems();
|
initializeSubsystems();
|
||||||
} catch (Exception exception) {
|
} catch (Exception exception) {
|
||||||
logger.crash("Subsystem dependency resolution failed", exception);
|
logger.error("Subsystem dependency resolution failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -232,11 +228,22 @@ public final class Engine extends SubsystemClass {
|
||||||
* Engine, if it isn't already.
|
* Engine, if it isn't already.
|
||||||
*
|
*
|
||||||
* @throws IllegalStateException when running in an incompatible environment
|
* @throws IllegalStateException when running in an incompatible environment
|
||||||
|
* @throws RuntimeException on engine initialization failure
|
||||||
* @since v1-alpha6
|
* @since v1-alpha6
|
||||||
*/
|
*/
|
||||||
public static void initialize() throws IllegalStateException {
|
public static void initialize() throws IllegalStateException, RuntimeException {
|
||||||
if (instance == null)
|
try {
|
||||||
instance = new Engine();
|
if (instance == null)
|
||||||
|
new Engine();
|
||||||
|
} catch (IllegalStateException exception) {
|
||||||
|
throw exception;
|
||||||
|
} catch (Exception exception) {
|
||||||
|
logger.error("Engine initialization failed");
|
||||||
|
logger.error(Miscellaneous.getStackTraceHeader(exception));
|
||||||
|
for (String line : Miscellaneous.getStackTraceAsString(exception, true).split("\n"))
|
||||||
|
logger.error(line);
|
||||||
|
throw new RuntimeException("Engine initialization failed", exception);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -59,7 +59,7 @@ public class PlainLoggingAdapter implements LoggingAdapter {
|
||||||
public void print(@NotNull LogLevel level, @NotNull Class<?> issuerClass, @NotNull String issuerOrigin, @Nullable String issuerMetadata, @NotNull String message, @NotNull String format) {
|
public void print(@NotNull LogLevel level, @NotNull Class<?> issuerClass, @NotNull String issuerOrigin, @Nullable String issuerMetadata, @NotNull String message, @NotNull String format) {
|
||||||
format = new EmptyShortcodeConverter(format, true).getClean();
|
format = new EmptyShortcodeConverter(format, true).getClean();
|
||||||
if (level == LogLevel.ERROR || level == LogLevel.CRASH)
|
if (level == LogLevel.ERROR || level == LogLevel.CRASH)
|
||||||
if (EngineConfiguration.getInstance().isLoggerForceStandardOutput())
|
if (EngineConfiguration.getInstance() != null && EngineConfiguration.getInstance().isLoggerForceStandardOutput())
|
||||||
System.out.println(format);
|
System.out.println(format);
|
||||||
else
|
else
|
||||||
System.err.println(format);
|
System.err.println(format);
|
||||||
|
|
|
@ -58,7 +58,7 @@ public final class InitLogger {
|
||||||
*/
|
*/
|
||||||
private static synchronized void log(@NotNull LogLevel level, @NotNull Class<?> issuerClass, @NotNull String issuerOrigin, @Nullable String issuerMetadata, @NotNull String message) {
|
private static synchronized void log(@NotNull LogLevel level, @NotNull Class<?> issuerClass, @NotNull String issuerOrigin, @Nullable String issuerMetadata, @NotNull String message) {
|
||||||
// Dismiss if level is not allowed
|
// Dismiss if level is not allowed
|
||||||
if (level.compareTo(EngineConfiguration.getInstance().getLoggerLevel()) < 0)
|
if ((EngineConfiguration.getInstance() != null && level.compareTo(EngineConfiguration.getInstance().getLoggerLevel()) < 0) || level.compareTo(LogLevel.INFORMATIONAL) < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Invoke LoggingAdapter#prePlaceholder
|
// Invoke LoggingAdapter#prePlaceholder
|
||||||
|
|
|
@ -32,7 +32,6 @@ import de.staropensource.engine.windowing.implementable.Window;
|
||||||
import de.staropensource.engine.windowing.type.input.Key;
|
import de.staropensource.engine.windowing.type.input.Key;
|
||||||
import de.staropensource.engine.windowing.type.input.KeyState;
|
import de.staropensource.engine.windowing.type.input.KeyState;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.SneakyThrows;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
@ -100,7 +99,6 @@ public final class Main {
|
||||||
* @see #main(String[])
|
* @see #main(String[])
|
||||||
* @since v1-alpha0
|
* @since v1-alpha0
|
||||||
*/
|
*/
|
||||||
@SneakyThrows
|
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
// Specify subsystems to load
|
// Specify subsystems to load
|
||||||
|
@ -112,7 +110,11 @@ public final class Main {
|
||||||
);
|
);
|
||||||
|
|
||||||
// Initialize sos!engine
|
// Initialize sos!engine
|
||||||
Engine.initialize();
|
try {
|
||||||
|
Engine.initialize();
|
||||||
|
} catch (Exception exception) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Register events
|
// Register events
|
||||||
EventHelper.registerEvent(InputEvent.class, new EventListenerCode() {
|
EventHelper.registerEvent(InputEvent.class, new EventListenerCode() {
|
||||||
|
@ -166,7 +168,12 @@ public final class Main {
|
||||||
|
|
||||||
logger.crash(message.toString());
|
logger.crash(message.toString());
|
||||||
} catch (Exception exception) {
|
} catch (Exception exception) {
|
||||||
logger.crash("The main thread threw an exception", exception);
|
System.err.println("Caught throwable in main thread:");
|
||||||
|
System.err.println(Miscellaneous.getStackTraceHeader(exception));
|
||||||
|
System.err.println(Miscellaneous.getStackTraceAsString(exception, true));
|
||||||
|
|
||||||
|
// Halt JVM
|
||||||
|
Runtime.getRuntime().halt(255);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue