From f8c4009f19108d51f770e6770d746ee6117eca61 Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Tue, 31 Jul 2018 19:31:21 -0500 Subject: [PATCH] fixed error handling for edit commands --- Commands.py | 19 +++++++++++++++++++ Geoffrey.py | 2 ++ 2 files changed, 21 insertions(+) diff --git a/Commands.py b/Commands.py index 3e9cb45..013439b 100644 --- a/Commands.py +++ b/Commands.py @@ -192,6 +192,12 @@ class Commands: session.commit() loc_str = location.__str__() + except IntegrityError: + session.rollback() + raise EntryNameNotUniqueError + except DataError: + session.rollback() + raise DatabaseValueError except IndexError: raise LocationLookUpError finally: @@ -215,6 +221,12 @@ class Commands: loc_str = location.__str__() session.commit() + except IntegrityError: + session.rollback() + raise EntryNameNotUniqueError + except DataError: + session.rollback() + raise DatabaseValueError except IndexError: raise LocationLookUpError finally: @@ -232,6 +244,13 @@ class Commands: location.name = new_name loc_str = location.__str__() session.commit() + + except IntegrityError: + session.rollback() + raise EntryNameNotUniqueError + except DataError: + session.rollback() + raise DatabaseValueError except IndexError: raise LocationLookUpError finally: diff --git a/Geoffrey.py b/Geoffrey.py index 4d359a6..e8fe9f4 100644 --- a/Geoffrey.py +++ b/Geoffrey.py @@ -355,6 +355,8 @@ async def edit_tunnel(ctx, tunnel_color: str, tunnel_number: int, * args): except LocationLookUpError: await bot.say('{}, you do not have a location called **{}**.'.format( ctx.message.author.mention, loc)) + except InvalidTunnelError: + await bot.say('{}, {} is an invalid tunnel color.'.format(ctx.message.author.mention, tunnel_color)) @commands.cooldown(5, 60, commands.BucketType.user) @bot.command(pass_context=True)