From 6d649d0889835c6392b73d83f4a5c1bdbee5c3c0 Mon Sep 17 00:00:00 2001 From: William Date: Fri, 7 Oct 2022 14:20:48 +0100 Subject: [PATCH] Extra logging for DataSerialization exceptions --- .../net/william278/husksync/data/BukkitSerializer.java | 8 ++++++++ .../java/net/william278/husksync/redis/RedisManager.java | 2 ++ 2 files changed, 10 insertions(+) diff --git a/bukkit/src/main/java/net/william278/husksync/data/BukkitSerializer.java b/bukkit/src/main/java/net/william278/husksync/data/BukkitSerializer.java index 28032ab5..03828631 100644 --- a/bukkit/src/main/java/net/william278/husksync/data/BukkitSerializer.java +++ b/bukkit/src/main/java/net/william278/husksync/data/BukkitSerializer.java @@ -1,5 +1,6 @@ package net.william278.husksync.data; +import net.william278.husksync.BukkitHuskSync; import org.bukkit.inventory.ItemStack; import org.bukkit.potion.PotionEffect; import org.bukkit.util.io.BukkitObjectInputStream; @@ -13,6 +14,7 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Map; import java.util.concurrent.CompletableFuture; +import java.util.logging.Level; public class BukkitSerializer { @@ -25,6 +27,8 @@ public class BukkitSerializer { public static CompletableFuture serializeItemStackArray(@NotNull ItemStack[] inventoryContents) throws DataSerializationException { return CompletableFuture.supplyAsync(() -> { + BukkitHuskSync.getInstance().getLoggingAdapter().debug("[HS] Serializing inventory contents"); + // Return an empty string if there is no inventory item data to serialize if (inventoryContents.length == 0) { return ""; @@ -45,6 +49,7 @@ public class BukkitSerializer { // Return encoded data, using the encoder from SnakeYaml to get a ByteArray conversion return Base64Coder.encodeLines(byteOutputStream.toByteArray()); } catch (IOException e) { + BukkitHuskSync.getInstance().getLoggingAdapter().log(Level.SEVERE, "Failed to serialize item stack data", e); throw new DataSerializationException("Failed to serialize item stack data", e); } }); @@ -95,6 +100,7 @@ public class BukkitSerializer { return inventoryContents; } } catch (IOException | ClassNotFoundException e) { + BukkitHuskSync.getInstance().getLoggingAdapter().log(Level.SEVERE, "Failed to deserialize item stack data", e); throw new DataSerializationException("Failed to deserialize item stack data", e); } }); @@ -151,6 +157,7 @@ public class BukkitSerializer { // Return encoded data, using the encoder from SnakeYaml to get a ByteArray conversion return Base64Coder.encodeLines(byteOutputStream.toByteArray()); } catch (IOException e) { + BukkitHuskSync.getInstance().getLoggingAdapter().log(Level.SEVERE, "Failed to serialize potion effect data", e); throw new DataSerializationException("Failed to serialize potion effect data", e); } }); @@ -186,6 +193,7 @@ public class BukkitSerializer { return potionEffects; } } catch (IOException | ClassNotFoundException e) { + BukkitHuskSync.getInstance().getLoggingAdapter().log(Level.SEVERE, "Failed to deserialize potion effect data", e); throw new DataSerializationException("Failed to deserialize potion effects", e); } }); diff --git a/common/src/main/java/net/william278/husksync/redis/RedisManager.java b/common/src/main/java/net/william278/husksync/redis/RedisManager.java index 949e41a1..5df81ede 100644 --- a/common/src/main/java/net/william278/husksync/redis/RedisManager.java +++ b/common/src/main/java/net/william278/husksync/redis/RedisManager.java @@ -130,6 +130,8 @@ public class RedisManager { jedis.setex(getKey(RedisKeyType.DATA_UPDATE, user.uuid), RedisKeyType.DATA_UPDATE.timeToLive, plugin.getDataAdapter().toBytes(userData)); + + // Debug logging plugin.getLoggingAdapter().debug("[" + user.username + "] Set " + RedisKeyType.DATA_UPDATE.name() + " key to redis at: " + new SimpleDateFormat("mm:ss.SSS").format(new Date()));