fixed error handling for edit commands

doc_update
Joey Hines 2018-07-31 19:31:21 -05:00
parent 5b0027668b
commit f8c4009f19
2 changed files with 21 additions and 0 deletions

View File

@ -192,6 +192,12 @@ class Commands:
session.commit() session.commit()
loc_str = location.__str__() loc_str = location.__str__()
except IntegrityError:
session.rollback()
raise EntryNameNotUniqueError
except DataError:
session.rollback()
raise DatabaseValueError
except IndexError: except IndexError:
raise LocationLookUpError raise LocationLookUpError
finally: finally:
@ -215,6 +221,12 @@ class Commands:
loc_str = location.__str__() loc_str = location.__str__()
session.commit() session.commit()
except IntegrityError:
session.rollback()
raise EntryNameNotUniqueError
except DataError:
session.rollback()
raise DatabaseValueError
except IndexError: except IndexError:
raise LocationLookUpError raise LocationLookUpError
finally: finally:
@ -232,6 +244,13 @@ class Commands:
location.name = new_name location.name = new_name
loc_str = location.__str__() loc_str = location.__str__()
session.commit() session.commit()
except IntegrityError:
session.rollback()
raise EntryNameNotUniqueError
except DataError:
session.rollback()
raise DatabaseValueError
except IndexError: except IndexError:
raise LocationLookUpError raise LocationLookUpError
finally: finally:

View File

@ -355,6 +355,8 @@ async def edit_tunnel(ctx, tunnel_color: str, tunnel_number: int, * args):
except LocationLookUpError: except LocationLookUpError:
await bot.say('{}, you do not have a location called **{}**.'.format( await bot.say('{}, you do not have a location called **{}**.'.format(
ctx.message.author.mention, loc)) 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) @commands.cooldown(5, 60, commands.BucketType.user)
@bot.command(pass_context=True) @bot.command(pass_context=True)