Update/Fix engine init exception handling + errors
Some checks failed
build-and-test / generate-javadoc (push) Failing after 1m6s
build-and-test / build (push) Failing after 1m11s
build-and-test / test (push) Has been cancelled

This commit is contained in:
JeremyStar™ 2024-10-14 15:48:54 +02:00
parent 9d19dd8b57
commit 2f0bc19e7c
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D
4 changed files with 29 additions and 15 deletions

View file

@ -186,12 +186,8 @@ public final class Engine extends SubsystemClass {
* @since v1-alpha6
*/
private Engine() throws IllegalStateException {
if (instance == null)
instance = this;
else
return;
long initTime = Miscellaneous.measureExecutionTime(() -> {
instance = this;
state = EngineState.EARLY_STARTUP;
new EngineConfiguration();
@ -217,7 +213,7 @@ public final class Engine extends SubsystemClass {
try {
initializeSubsystems();
} 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.
*
* @throws IllegalStateException when running in an incompatible environment
* @throws RuntimeException on engine initialization failure
* @since v1-alpha6
*/
public static void initialize() throws IllegalStateException {
if (instance == null)
instance = new Engine();
public static void initialize() throws IllegalStateException, RuntimeException {
try {
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);
}
}
/**

View file

@ -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) {
format = new EmptyShortcodeConverter(format, true).getClean();
if (level == LogLevel.ERROR || level == LogLevel.CRASH)
if (EngineConfiguration.getInstance().isLoggerForceStandardOutput())
if (EngineConfiguration.getInstance() != null && EngineConfiguration.getInstance().isLoggerForceStandardOutput())
System.out.println(format);
else
System.err.println(format);

View file

@ -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) {
// 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;
// Invoke LoggingAdapter#prePlaceholder

View file

@ -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.KeyState;
import lombok.Getter;
import lombok.SneakyThrows;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -100,7 +99,6 @@ public final class Main {
* @see #main(String[])
* @since v1-alpha0
*/
@SneakyThrows
public void run() {
try {
// Specify subsystems to load
@ -112,7 +110,11 @@ public final class Main {
);
// Initialize sos!engine
Engine.initialize();
try {
Engine.initialize();
} catch (Exception exception) {
return;
}
// Register events
EventHelper.registerEvent(InputEvent.class, new EventListenerCode() {
@ -166,7 +168,12 @@ public final class Main {
logger.crash(message.toString());
} 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);
}
}