From 6ff6ec9d6b21f3900ca7d9a2e091a870574b5c04 Mon Sep 17 00:00:00 2001 From: Minecon724 Date: Mon, 3 Feb 2025 10:52:04 +0100 Subject: [PATCH] fix: improve error handling in ChatCommands Updated error handling to throw RuntimeException instead of printing stack traces. Enhanced user feedback by standardizing error messages across various chat command operations. Signed-off-by: Minecon724 --- .../eu/m724/tweaks/module/chat/ChatCommands.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/eu/m724/tweaks/module/chat/ChatCommands.java b/src/main/java/eu/m724/tweaks/module/chat/ChatCommands.java index d6fa1ba..a9f6f50 100644 --- a/src/main/java/eu/m724/tweaks/module/chat/ChatCommands.java +++ b/src/main/java/eu/m724/tweaks/module/chat/ChatCommands.java @@ -99,8 +99,8 @@ public class ChatCommands implements CommandExecutor { } catch (ChatModule.ChatRoomExistsException e) { sender.sendMessage("Room %s already exists".formatted(argument)); } catch (IOException e) { - sender.sendMessage("Failed to create room"); - e.printStackTrace(); + sender.sendMessage("Error creating room"); + throw new RuntimeException(e); } } case "delete" -> { @@ -124,8 +124,8 @@ public class ChatCommands implements CommandExecutor { manager.saveChatRoom(chatRoom); sender.sendMessage("Owner changed to " + newOwner.getName()); } catch (IOException e) { - sender.sendMessage("Failed to change owner"); - e.printStackTrace(); + sender.sendMessage("Error changing owner"); + throw new RuntimeException(e); } } else { sender.sendMessage("Player must be online"); @@ -141,8 +141,8 @@ public class ChatCommands implements CommandExecutor { manager.saveChatRoom(chatRoom); sender.sendMessage("Password changed"); } catch (IOException e) { - sender.sendMessage("Failed to change password"); - e.printStackTrace(); + sender.sendMessage("Error changing password"); + throw new RuntimeException(e); } } else { sender.sendMessage("You're not the owner of %s, please enter the room you want to make changes in".formatted(chatRoom.id)); @@ -157,8 +157,8 @@ public class ChatCommands implements CommandExecutor { manager.saveChatRoom(chatRoom); sender.sendMessage("Message color changed to " + newColor.getName()); } catch (IOException e) { - sender.sendMessage("Failed to change color"); - e.printStackTrace(); + sender.sendMessage("Error changing color"); + throw new RuntimeException(e); } } else { sender.sendMessage("Invalid color");