From 98dd5e421226049f3c3cd86d545449bce55a653a Mon Sep 17 00:00:00 2001 From: b3yond Date: Thu, 4 Jan 2018 12:20:59 +0100 Subject: [PATCH] improved the traceback messages --- retootbot.py | 15 ++++++++++----- retweetbot.py | 15 ++++++++++----- ticketfrei.py | 12 +++++++++--- 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/retootbot.py b/retootbot.py index a87f92b..1c06882 100755 --- a/retootbot.py +++ b/retootbot.py @@ -130,9 +130,14 @@ if __name__ == '__main__': bot.retoot() time.sleep(1) except KeyboardInterrupt: - print("Good bye! Remember to restart the bot.") + print("Good bye. Remember to restart the bot!") except: - tb = traceback.extract_tb(sys.exc_info()[2]) - bot.logger.log(tb) - print() - bot.shutdown(tb) + exc = sys.exc_info() # returns tuple [Exception type, Exception object, Traceback object] + tb = traceback.extract_tb(exc[2]) # returns StackSummary object + tb = "\n".join(tb.format()) # string of the actual traceback + message = ("Traceback (most recent call last):\n", + tb, + exc[0].__name__) # the type of the Exception + message = "".join(message) # concatenate to full traceback message + bot.logger.log(message) + bot.shutdown(message) diff --git a/retweetbot.py b/retweetbot.py index 8fd50b4..a4b9873 100755 --- a/retweetbot.py +++ b/retweetbot.py @@ -251,9 +251,14 @@ if __name__ == "__main__": bot.flow() sleep(60) except KeyboardInterrupt: - print("Good bye! Remember to restart the bot.") + print("Good bye. Remember to restart the bot!") except: - tb = traceback.extract_tb(sys.exc_info()[2]) - bot.logger.log(tb) - print() - bot.shutdown(tb) + exc = sys.exc_info() # returns tuple [Exception type, Exception object, Traceback object] + tb = traceback.extract_tb(exc[2]) # returns StackSummary object + tb = "\n".join(tb.format()) # string of the actual traceback + message = ("Traceback (most recent call last):\n", + tb, + exc[0].__name__) # the type of the Exception + message = "".join(message) # concatenate to full traceback message + bot.logger.log(message) + bot.shutdown(message) diff --git a/ticketfrei.py b/ticketfrei.py index 9176383..58c2819 100755 --- a/ticketfrei.py +++ b/ticketfrei.py @@ -35,6 +35,12 @@ if __name__ == '__main__': except KeyboardInterrupt: print("Good bye. Remember to restart the bot!") except: - tb = traceback.extract_tb(sys.exc_info()[2]) - tbot.logger.log(tb) - tbot.shutdown(tb) + exc = sys.exc_info() # returns tuple [Exception type, Exception object, Traceback object] + tb = traceback.extract_tb(exc[2]) # returns StackSummary object + tb = "\n".join(tb.format()) # string of the actual traceback + message = ("Traceback (most recent call last):\n", + tb, + exc[0].__name__) # the type of the Exception + message = "".join(message) # concatenate to full traceback message + tbot.logger.log(message) + tbot.shutdown(message)