log traceback of all unexpected Exceptions

This commit is contained in:
b3yond 2018-01-05 10:52:15 +01:00
parent 31a54fc19f
commit 0b89a52da3
2 changed files with 21 additions and 10 deletions

View file

@ -49,7 +49,9 @@ class Logger(object):
try: try:
f.write(line) f.write(line)
except UnicodeEncodeError: except UnicodeEncodeError:
self.log("Failed to save log message due to UTF-8 error. ") message = "Failed to save log message due to UTF-8 error. "
message = message + self.generate_tb(sys.exc_info())
self.log(message)
print(line, end="") print(line, end="")
def generate_tb(self, exc): def generate_tb(self, exc):
@ -76,5 +78,5 @@ class Logger(object):
mailer = sendmail.Mailer(self.config) mailer = sendmail.Mailer(self.config)
mailer.send(tb, self.contact, "Ticketfrei Crash Report") mailer.send(tb, self.contact, "Ticketfrei Crash Report")
except: except:
self.log(self.generate_tb(sys.exc_info())) self.log("Error while shutdown: " + self.generate_tb(sys.exc_info()))
print() print()

View file

@ -134,10 +134,14 @@ class RetweetBot(object):
mentions = self.api.mentions_timeline(since_id=self.last_mention) mentions = self.api.mentions_timeline(since_id=self.last_mention)
return mentions return mentions
except tweepy.RateLimitError: except tweepy.RateLimitError:
self.logger.log("Twitter API Error: Rate Limit Exceeded.") message = "Twitter API Error: Rate Limit Exceeded."
message = message + self.logger.generate_tb(sys.exc_info())
self.logger.log(message)
self.waitcounter += 60*15 + 1 self.waitcounter += 60*15 + 1
except requests.exceptions.ConnectionError: except requests.exceptions.ConnectionError:
self.logger.log("Twitter API Error: Bad Connection.") message = "Twitter API Error: Bad Connection."
message = message + self.logger.generate_tb(sys.exc_info())
self.logger.log(message)
self.waitcounter += 10 self.waitcounter += 10
return None return None
@ -155,13 +159,16 @@ class RetweetBot(object):
if status.id > self.last_mention: if status.id > self.last_mention:
self.last_mention = status.id self.last_mention = status.id
return self.format_mastodon(status) return self.format_mastodon(status)
# maybe one day we get rid of this error. If not, try to uncomment
# these lines.
except requests.exceptions.ConnectionError: except requests.exceptions.ConnectionError:
self.logger.log("Twitter API Error: Bad Connection.") message = "Twitter API Error: Bad Connection."
message = message + self.logger.generate_tb(sys.exc_info())
self.logger.log(message)
sleep(10) sleep(10)
except tweepy.TweepError as error: # maybe one day we get rid of this error:
self.logger.log("Twitter Error " + error.api_code + ": " + error.reason + error.response) except tweepy.TweepError:
message = "Twitter Error."
message = message + self.logger.generate_tb(sys.exc_info())
self.logger.log(message)
# self.log.log("Twitter API Error: You probably already retweeted this tweet: " + status.text) # self.log.log("Twitter API Error: You probably already retweeted this tweet: " + status.text)
if status.id > self.last_mention: if status.id > self.last_mention:
self.last_mention = status.id self.last_mention = status.id
@ -180,7 +187,9 @@ class RetweetBot(object):
self.api.update_status(status=post) self.api.update_status(status=post)
return return
except requests.exceptions.ConnectionError: except requests.exceptions.ConnectionError:
self.logger.log("Twitter API Error: Bad Connection.") message = "Twitter API Error: Bad Connection."
message = message + self.logger.generate_tb(sys.exc_info())
self.logger.log(message)
sleep(10) sleep(10)
def flow(self, to_tweet=()): def flow(self, to_tweet=()):