From b15dfbc1ec859c75271c34e3883c3fcc869e2b63 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sun, 23 Oct 2016 05:49:01 -0600 Subject: [PATCH] Don't catch the exceptions we throw in SetUserGroup For some reason, we were catching our own exceptions and then throwing UesrManagerExceptions despite the fact that we explicitly threw more specific exceptions. Fixes #1315. --- CHANGELOG.md | 1 + TShockAPI/DB/UserManager.cs | 14 +++++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d66fea41..8373292e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * `/status` * `/v2/players/read` * `/v2/server/rawcmd` (@WhiteXZ). +* Fixed `/user group` always giving an unhelpful error messaging telling you to check the console, even if we knew exactly why it failed (@nicatronTg). ## TShock 4.3.20 * Security improvement: The auth system is now automatically disabled if a superadmin exists in the database (@Enerdy). diff --git a/TShockAPI/DB/UserManager.cs b/TShockAPI/DB/UserManager.cs index cab87922..c27ffd46 100755 --- a/TShockAPI/DB/UserManager.cs +++ b/TShockAPI/DB/UserManager.cs @@ -158,15 +158,15 @@ namespace TShockAPI.DB /// string group public void SetUserGroup(User user, string group) { + Group grp = TShock.Groups.GetGroupByName(group); + if (null == grp) + throw new GroupNotExistsException(group); + + if (_database.Query("UPDATE Users SET UserGroup = @0 WHERE Username = @1;", group, user.Name) == 0) + throw new UserNotExistException(user.Name); + try { - Group grp = TShock.Groups.GetGroupByName(group); - if (null == grp) - throw new GroupNotExistsException(group); - - if (_database.Query("UPDATE Users SET UserGroup = @0 WHERE Username = @1;", group, user.Name) == 0) - throw new UserNotExistException(user.Name); - // Update player group reference for any logged in player foreach (var player in TShock.Players.Where(p => p != null && p.User != null && p.User.Name == user.Name)) {