Skip to content

Commit

Permalink
BAD HACK -- why does Decimal.__sub__ do this??
Browse files Browse the repository at this point in the history
  • Loading branch information
DigiDuncan committed Oct 31, 2024
1 parent 7e8aab4 commit c9439c5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
16 changes: 8 additions & 8 deletions sizebot/extensions/errorhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@ async def on_command_error(ctx: BotContext, error: commands.CommandError):
if isinstance(err, errors.DigiContextException):
# DigiContextException handling
message = await err.formatMessage(ctx)
if message is not None:
logger.log(err.level, message)
logger.error(utils.format_traceback(error))
# if message is not None:
# logger.log(err.level, message)
# logger.error(utils.format_traceback(error))
userMessage = await err.formatUserMessage(ctx)
if userMessage is not None:
await ctx.send(f"{emojis.warning} {userMessage}")
elif isinstance(err, errors.DigiException):
# DigiException handling
message = err.formatMessage()
if message is not None:
logger.log(err.level, message)
logger.error(utils.format_traceback(error))
# if message is not None:
# logger.log(err.level, message)
# logger.error(utils.format_traceback(error))
userMessage = err.formatUserMessage()
if userMessage is not None:
await ctx.send(f"{emojis.warning} {userMessage}")
Expand All @@ -72,8 +72,8 @@ async def on_command_error(ctx: BotContext, error: commands.CommandError):
else:
# Default command error handling
await ctx.send(f"{emojis.error} Something went wrong.")
logger.error(f"Ignoring exception in command {ctx.command}:")
logger.error(utils.format_traceback(error))
logger.error(f"Ignoring exception in command {ctx.command}:")
logger.error(utils.format_traceback(error))

@bot.event
async def on_error(event: discord.DiscordException, *args, **kwargs):
Expand Down
5 changes: 4 additions & 1 deletion sizebot/lib/digidecimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,10 @@ def __radd__(self, other: BaseDecimal | int) -> BaseDecimal:
def __sub__(self, other: BaseDecimal | int) -> BaseDecimal:
rawvalue = unwrap_decimal(self)
rawother = unwrap_decimal(other)
return BaseDecimal(rawvalue - rawother)
try:
return BaseDecimal(rawvalue - rawother)
except decimal.InvalidOperation as e:
return BaseDecimal(0)

@abstractmethod
def __rsub__(self, other: BaseDecimal | int) -> BaseDecimal:
Expand Down

0 comments on commit c9439c5

Please sign in to comment.