Skip to content

Commit c61f7c5

Browse files
committed
[Chore] Replace e.printstacktrace with exception manager call or logger
1 parent 13f484f commit c61f7c5

File tree

8 files changed

+17
-9
lines changed

8 files changed

+17
-9
lines changed

src/main/java/net/minestom/server/entity/PlayerProjectile.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public void shoot(@NotNull Point from, @NotNull Point to, double power, double s
9898

9999
this.setInstance(instance, new Pos(from.x(), from.y(), from.z(), yaw, pitch)).whenComplete((result, throwable) -> {
100100
if (throwable != null) {
101-
throwable.printStackTrace();
101+
MinecraftServer.getExceptionManager().handleException(throwable);
102102
} else {
103103
this.setVelocity(v);
104104
}

src/main/java/net/minestom/server/exception/ExceptionManager.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22

33
import net.minestom.server.MinecraftServer;
44
import org.jetbrains.annotations.Nullable;
5+
import org.slf4j.Logger;
6+
import org.slf4j.LoggerFactory;
57

68
/**
79
* Manages the handling of exceptions.
810
*/
911
public final class ExceptionManager {
1012

13+
private static final Logger LOGGER = LoggerFactory.getLogger(ExceptionManager.class);
14+
1115
private ExceptionHandler exceptionHandler;
1216

1317
/**
@@ -18,7 +22,7 @@ public final class ExceptionManager {
1822
public void handleException(Throwable e) {
1923
if (e instanceof OutOfMemoryError) {
2024
// OOM should be handled manually
21-
e.printStackTrace();
25+
LOGGER.error("OOM error", e);
2226
MinecraftServer.stopCleanly();
2327
return;
2428
}

src/main/java/net/minestom/server/extras/velocity/VelocityProxy.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package net.minestom.server.extras.velocity;
22

3+
import net.minestom.server.MinecraftServer;
34
import net.minestom.server.extras.MojangAuth;
45
import net.minestom.server.network.NetworkBuffer;
56
import net.minestom.server.utils.validate.Check;
@@ -66,7 +67,7 @@ public static boolean checkIntegrity(@NotNull NetworkBuffer buffer) {
6667
return false;
6768
}
6869
} catch (NoSuchAlgorithmException | InvalidKeyException e) {
69-
e.printStackTrace();
70+
MinecraftServer.getExceptionManager().handleException(e);
7071
}
7172
final int version = buffer.read(VAR_INT);
7273
return version == SUPPORTED_FORWARDING_VERSION;

src/main/java/net/minestom/server/instance/AnvilLoader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ private void loadBlockEntities(Chunk loadedChunk, ChunkReader chunkReader) {
316316
try (NBTWriter writer = new NBTWriter(Files.newOutputStream(levelPath))) {
317317
writer.writeNamed("", nbt);
318318
} catch (IOException e) {
319-
e.printStackTrace();
319+
MinecraftServer.getExceptionManager().handleException(e);
320320
}
321321
return AsyncUtils.VOID_FUTURE;
322322
}

src/main/java/net/minestom/server/instance/batch/ChunkBatch.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
55
import it.unimi.dsi.fastutil.ints.IntArraySet;
66
import it.unimi.dsi.fastutil.ints.IntSet;
7+
import net.minestom.server.MinecraftServer;
78
import net.minestom.server.instance.Chunk;
89
import net.minestom.server.instance.Instance;
910
import net.minestom.server.instance.InstanceContainer;
@@ -193,7 +194,7 @@ private void singleThreadFlush(Instance instance, Chunk chunk, @Nullable ChunkBa
193194
if (inverse != null) inverse.readyLatch.countDown();
194195
updateChunk(instance, chunk, sections, callback, safeCallback);
195196
} catch (Exception e) {
196-
e.printStackTrace();
197+
MinecraftServer.getExceptionManager().handleException(e);
197198
}
198199
}
199200

src/main/java/net/minestom/server/network/socket/Server.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public void start() {
8585
final SocketChannel client = serverSocket.accept();
8686
worker.receiveConnection(client);
8787
} catch (IOException e) {
88-
e.printStackTrace();
88+
MinecraftServer.getExceptionManager().handleException(e);
8989
}
9090
});
9191
} catch (IOException e) {

src/main/java/net/minestom/server/tag/TagNbtSeparator.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package net.minestom.server.tag;
22

3+
import net.minestom.server.MinecraftServer;
4+
import net.minestom.server.exception.ExceptionManager;
35
import org.jglrxavpok.hephaistos.nbt.NBT;
46
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
57
import org.jglrxavpok.hephaistos.nbt.NBTList;
@@ -74,7 +76,7 @@ private static void convert(List<String> path, String key, NBT nbt, Consumer<Ent
7476
}
7577
consumer.accept(makeEntry(path, Tag.class.cast(tag), List.of(values)));
7678
} catch (Exception e) {
77-
e.printStackTrace();
79+
MinecraftServer.getExceptionManager().handleException(e);
7880
consumer.accept(makeEntry(path, Tag.NBT(key), nbt));
7981
}
8082
}

src/main/java/net/minestom/server/terminal/MinestomTerminal.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public static void start() {
3131
try {
3232
terminal = TerminalBuilder.terminal();
3333
} catch (IOException e) {
34-
e.printStackTrace();
34+
MinecraftServer.getExceptionManager().handleException(e);
3535
}
3636
reader = LineReaderBuilder.builder()
3737
.completer(new MinestomCompleter())
@@ -65,7 +65,7 @@ public static void stop() {
6565
try {
6666
terminal.close();
6767
} catch (IOException e) {
68-
e.printStackTrace();
68+
MinecraftServer.getExceptionManager().handleException(e);
6969
}
7070
reader = null;
7171
}

0 commit comments

Comments
 (0)