From 61fb1c249c09c2764ad49147bd4c29984bff052f Mon Sep 17 00:00:00 2001 From: KennyTV Date: Thu, 2 Jul 2020 11:08:59 +0200 Subject: [PATCH] Wrap exceptions in remappers to InformativeEx --- .../myles/ViaVersion/api/protocol/Protocol.java | 7 ++++--- .../ViaVersion/api/remapper/PacketRemapper.java | 16 ++++++++++++++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/common/src/main/java/us/myles/ViaVersion/api/protocol/Protocol.java b/common/src/main/java/us/myles/ViaVersion/api/protocol/Protocol.java index 280836879..c6f9c5b6a 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/protocol/Protocol.java +++ b/common/src/main/java/us/myles/ViaVersion/api/protocol/Protocol.java @@ -8,6 +8,7 @@ import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.platform.providers.ViaProviders; import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.exception.CancelException; +import us.myles.ViaVersion.exception.InformativeException; import us.myles.ViaVersion.packets.Direction; import us.myles.ViaVersion.packets.State; @@ -417,9 +418,9 @@ public abstract class Protocol The new return type. */ public void map(ValueTransformer transformer) { - if (transformer.getInputType() == null) throw new IllegalArgumentException("Use map(Type, ValueTransformer) for value transformers without specified input type!"); + if (transformer.getInputType() == null) { + throw new IllegalArgumentException("Use map(Type, ValueTransformer) for value transformers without specified input type!"); + } map(transformer.getInputType(), transformer); } @@ -116,7 +119,8 @@ public abstract class PacketRemapper { * Remap a packet wrapper * * @param packetWrapper The wrapper to remap - * @throws Exception Throws if it fails to write / read to the packet. + * @throws InformativeException if it fails to write / read to the packet + * @throws CancelException if the packet should be cancelled */ public void remap(PacketWrapper packetWrapper) throws Exception { try { @@ -130,6 +134,14 @@ public abstract class PacketRemapper { } catch (InformativeException e) { e.addSource(this.getClass()); throw e; + } catch (CancelException e) { + // Pass through CancelExceptions + throw e; + } catch (Exception e) { + // Wrap other exceptions during packet handling + InformativeException ex = new InformativeException(e); + ex.addSource(this.getClass()); + throw ex; } } }