Skip to content

Commit

Permalink
feat: improve error output (#545)
Browse files Browse the repository at this point in the history
  • Loading branch information
harry-xi authored Jan 19, 2025
1 parent c8aee70 commit 8c1b7aa
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ Unless otherwise specified, any version comparison below is the comparison of se
### Changed

- (API) Renamed `FullContainerTypeBuilder` to `Builder`
- World will be skipped if failed to be load.
- Main thread will sleep a short time if gui is enabled when the server exits abnormally. This gives user time to see what goes wrong.

## [0.1.3](https://github.com/AllayMC/Allay/releases/tag/0.1.3) (API 0.4.0) - 2025-1-17

Expand Down
10 changes: 9 additions & 1 deletion server/src/main/java/org/allaymc/server/Allay.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
import java.nio.file.Path;
import java.util.HashMap;

import static java.lang.Thread.sleep;

/**
* @author daoge_cmd
*/
Expand All @@ -64,7 +66,7 @@ public final class Allay {

public static Dashboard DASHBOARD;

public static void main(String[] args) {
public static void main(String[] args) throws InterruptedException {
long initialTime = System.currentTimeMillis();
if (GitProperties.isDevBuild() && !Server.SETTINGS.genericSettings().forceEnableSentry()) {
// Enable sentry only in non-dev build
Expand Down Expand Up @@ -98,6 +100,9 @@ public static void main(String[] args) {
initAllay();
} catch (Exception e) {
log.error("Cannot init Allay API!", e);
if(DASHBOARD != null) {
sleep(5000);
}
System.exit(1);
}

Expand All @@ -107,6 +112,9 @@ public static void main(String[] args) {
log.error("Error while starting the server!", t);
// The server may not be initialized correctly
// So we can't call Server::shutdown() to stop the server
if(DASHBOARD != null) {
sleep(5000);
}
System.exit(1);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@ public AllayWorldPool() {
}

public void loadWorlds() {
worldConfig.worlds().forEach(this::loadWorld);
worldConfig.worlds().forEach((name, setting) -> {
try {
this.loadWorld(name, setting);
} catch (Exception e) {
log.error("Error when loading world {}, skipped.", name, e);
}
});
}

public void shutdown() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ public class AllayTestExtension implements BeforeAllCallback {
@Override
public void beforeAll(ExtensionContext context) {
if (!AllayAPI.getInstance().isImplemented()) {
Thread.ofPlatform().name("Test Main Thread").start(() -> Allay.main(new String[]{}));
Thread.ofPlatform().name("Test Main Thread").start(() -> {
try {
Allay.main(new String[]{});
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
});
while (Server.getInstance() == null || Server.getInstance().isStarting()) {
try {
Thread.sleep(100);
Expand Down

0 comments on commit 8c1b7aa

Please sign in to comment.