only print some exceptions when in LogLevel >= DEBUG

This commit is contained in:
Bixilon 2020-09-04 14:03:34 +02:00
parent 480e5db1ab
commit 6a5862f6d0
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
4 changed files with 23 additions and 6 deletions

View File

@ -23,6 +23,7 @@ import de.bixilon.minosoft.game.datatypes.objectLoader.recipes.Recipes;
import de.bixilon.minosoft.game.datatypes.objectLoader.versions.Version;
import de.bixilon.minosoft.game.datatypes.objectLoader.versions.Versions;
import de.bixilon.minosoft.logging.Log;
import de.bixilon.minosoft.logging.LogLevels;
import de.bixilon.minosoft.ping.ServerListPing;
import de.bixilon.minosoft.protocol.modding.channels.DefaultPluginChannels;
import de.bixilon.minosoft.protocol.modding.channels.PluginChannelHandler;
@ -217,7 +218,9 @@ public class Connection {
try {
Versions.loadVersionMappings(version.getProtocolVersion());
} catch (IOException e) {
if (Log.getLevel().ordinal() >= LogLevels.DEBUG.ordinal()) {
e.printStackTrace();
}
Log.fatal(String.format("Could not load mapping for %s. This version seems to be unsupported!", version));
network.lastException = new RuntimeException(String.format("Mappings could not be loaded: %s", e.getLocalizedMessage()));
setConnectionState(ConnectionStates.FAILED_NO_RETRY);
@ -267,9 +270,11 @@ public class Connection {
packet.log();
packet.handle(getHandler());
} catch (Exception e) {
if (Log.getLevel().ordinal() >= LogLevels.DEBUG.ordinal()) {
e.printStackTrace();
}
}
}
});
handleThread.setName(String.format("%d/Handling", connectionId));
handleThread.start();

View File

@ -14,6 +14,7 @@
package de.bixilon.minosoft.protocol.network;
import de.bixilon.minosoft.logging.Log;
import de.bixilon.minosoft.logging.LogLevels;
import de.bixilon.minosoft.protocol.packets.ClientboundPacket;
import de.bixilon.minosoft.protocol.packets.ServerboundPacket;
import de.bixilon.minosoft.protocol.packets.clientbound.interfaces.PacketCompressionInterface;
@ -227,9 +228,11 @@ public class Network {
}
} catch (Exception e) {
Log.protocol(String.format("An error occurred while parsing an packet (%s): %s", packet, e));
if (Log.getLevel().ordinal() >= LogLevels.DEBUG.ordinal()) {
e.printStackTrace();
}
}
}
disconnect();
} catch (IOException e) {
// Could not connect
@ -238,8 +241,10 @@ public class Network {
if (socketSThread != null) {
socketSThread.interrupt();
}
if (Log.getLevel().ordinal() >= LogLevels.DEBUG.ordinal()) {
e.printStackTrace();
}
}
});
socketRThread.setName(String.format("%d/Socket", connection.getConnectionId()));
socketRThread.start();

View File

@ -14,6 +14,8 @@
package de.bixilon.minosoft.util;
import com.google.gson.JsonObject;
import de.bixilon.minosoft.logging.Log;
import de.bixilon.minosoft.logging.LogLevels;
import java.io.IOException;
import java.net.URI;
@ -33,8 +35,10 @@ public final class HTTP {
try {
return client.send(request, HttpResponse.BodyHandlers.ofString());
} catch (IOException | InterruptedException e) {
if (Log.getLevel().ordinal() >= LogLevels.DEBUG.ordinal()) {
e.printStackTrace();
}
}
return null;
}

View File

@ -18,6 +18,7 @@ import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.JsonParser;
import de.bixilon.minosoft.logging.Log;
import de.bixilon.minosoft.logging.LogLevels;
import de.bixilon.minosoft.util.HTTP;
import java.net.http.HttpResponse;
@ -52,7 +53,9 @@ public final class MojangStatus {
return ret;
} catch (NullPointerException | JsonParseException e) {
if (Log.getLevel().ordinal() >= LogLevels.DEBUG.ordinal()) {
e.printStackTrace();
}
return getUnknownStatusMap();
}
}