News for hackers. Stuff that matters.
Re:Handling exceptions in Python like a pro by gorpovitch on Thursday May 20, 2021 @02:38AM (#27218097)
When using a tool like Sentry, you might want to logger.exception(e) instead of a string error message, that way the whole stack trace with helpful debugging information (local variables...) is included in Sentry.
Re:Handling exceptions in Python like a pro by tmarice on Thursday May 20, 2021 @04:05AM (#27218622)
logger.exception is basically a shortcut for logger.error(exc_info=True), so there's no need for explicitly assigning e as an error message.
Re:Handling exceptions in Python like a pro by aidos on Thursday May 20, 2021 @03:11PM (#27225695)
And if you look carefully you’ll find that doing logger.exception(e) will just cast e as a string, which is just the message in the e. So you end up just sending the message twice (along with the stack trace).

Instead you can do logger.exception(“something helpful to give a little more context at a glance”)

Re:Handling exceptions in Python like a pro by nicbou on Thursday May 20, 2021 @03:48AM (#27218519)
You might also want to use formatted strings too as it allows some logging tools to group the messages together.