improved the traceback messages

This commit is contained in:
b3yond 2018-01-04 12:20:59 +01:00
parent aa45a8e814
commit 98dd5e4212
3 changed files with 29 additions and 13 deletions

View file

@ -130,9 +130,14 @@ if __name__ == '__main__':
bot.retoot() bot.retoot()
time.sleep(1) time.sleep(1)
except KeyboardInterrupt: except KeyboardInterrupt:
print("Good bye! Remember to restart the bot.") print("Good bye. Remember to restart the bot!")
except: except:
tb = traceback.extract_tb(sys.exc_info()[2]) exc = sys.exc_info() # returns tuple [Exception type, Exception object, Traceback object]
bot.logger.log(tb) tb = traceback.extract_tb(exc[2]) # returns StackSummary object
print() tb = "\n".join(tb.format()) # string of the actual traceback
bot.shutdown(tb) 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)

View file

@ -251,9 +251,14 @@ if __name__ == "__main__":
bot.flow() bot.flow()
sleep(60) sleep(60)
except KeyboardInterrupt: except KeyboardInterrupt:
print("Good bye! Remember to restart the bot.") print("Good bye. Remember to restart the bot!")
except: except:
tb = traceback.extract_tb(sys.exc_info()[2]) exc = sys.exc_info() # returns tuple [Exception type, Exception object, Traceback object]
bot.logger.log(tb) tb = traceback.extract_tb(exc[2]) # returns StackSummary object
print() tb = "\n".join(tb.format()) # string of the actual traceback
bot.shutdown(tb) 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)

View file

@ -35,6 +35,12 @@ if __name__ == '__main__':
except KeyboardInterrupt: except KeyboardInterrupt:
print("Good bye. Remember to restart the bot!") print("Good bye. Remember to restart the bot!")
except: except:
tb = traceback.extract_tb(sys.exc_info()[2]) exc = sys.exc_info() # returns tuple [Exception type, Exception object, Traceback object]
tbot.logger.log(tb) tb = traceback.extract_tb(exc[2]) # returns StackSummary object
tbot.shutdown(tb) 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)