TelethonianBotExt icon indicating copy to clipboard operation
TelethonianBotExt copied to clipboard

Update main.py

Open x0x8x opened this issue 5 years ago • 4 comments

Proposing to use stack trace along with logging

x0x8x avatar Oct 04 '20 10:10 x0x8x

try/except is used when you're going to handle the exception. If you do this:

try:
    error
except:
    pass

You are not handling the exception. You're ignoring it. In this case, try/except should not be used, and instead users should just let it error if they actually want useful information. I don't know why people add empty excepts so happily, that won't fix their errors, just silence them.

In any case, logging.exception('error!') inside except will do the same as traceback, so that module is not needed at all.

If you want to update the text to indicate that using empty except is a bad idea, go ahead, but otherwise I won't merge this suggestion.

Lonami avatar Oct 04 '20 10:10 Lonami

logging.exception('error!')


If raise the exception an error will be printed even using pass Correct me if I'm wrong...


logging.basicConfig(level=logging.WARNING)
logger = logging.getLogger('telethon')

try:
    error
except:
    logger.error
    raise

x0x8x avatar Oct 09 '20 06:10 x0x8x


P.S. also:

repr(e)

x0x8x avatar Oct 09 '20 06:10 x0x8x

raise will re-raise the error so Telethon's logging can log it. print is the wrong way to go to log errors. Again I'll accept if we suggest the user to remove try/except in handlers to see errors, but not this. It's far too verbose and not the right thing to do.

Lonami avatar Oct 09 '20 06:10 Lonami