Catch ValueError from utils.parse_number, to allow other code to deal with

complaining about invalid numbers
This commit is contained in:
jesopo 2018-10-14 15:27:49 +01:00
parent 40ffb6ce0e
commit 54ba3c888c

View file

@ -208,7 +208,10 @@ class Module(ModuleManager.BaseModule):
event["user"].nickname) event["user"].nickname)
return return
try:
coin_bet = utils.parse_number(coin_bet) coin_bet = utils.parse_number(coin_bet)
except ValueError:
pass
match = REGEX_FLOAT.match(coin_bet) match = REGEX_FLOAT.match(coin_bet)
if not match or round(decimal.Decimal(coin_bet), 2) <= DECIMAL_ZERO: if not match or round(decimal.Decimal(coin_bet), 2) <= DECIMAL_ZERO:
event["stderr"].write("%s: Please provide a number of coins to bet" event["stderr"].write("%s: Please provide a number of coins to bet"
@ -333,7 +336,10 @@ class Module(ModuleManager.BaseModule):
return return
for i, bet_amount in enumerate(bet_amounts): for i, bet_amount in enumerate(bet_amounts):
try:
bet_amount = utils.parse_number(bet_amount) bet_amount = utils.parse_number(bet_amount)
except ValueError:
pass
match = REGEX_FLOAT.match(bet_amount) match = REGEX_FLOAT.match(bet_amount)
if not match or round(decimal.Decimal(bet_amount), 2 if not match or round(decimal.Decimal(bet_amount), 2
) <= DECIMAL_ZERO: ) <= DECIMAL_ZERO: