Skip to content

Commit

Permalink
Add logging in case of exceptions
Browse files Browse the repository at this point in the history
To be able to debug failures.
  • Loading branch information
kh31d4r authored and mosbth committed Oct 15, 2024
1 parent baded18 commit e438975
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
1 change: 1 addition & 0 deletions irc_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ def readincoming(self):
try:
shutil.move(filename, self.CONFIG["dirDone"])
except Exception:
LOG.warning("Failed to move %s to %s. Deleting.", filename, self.CONFIG["dirDone"])
os.remove(filename)

def mainLoop(self):
Expand Down
20 changes: 14 additions & 6 deletions marvin_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
import calendar
import datetime
import json
import logging
import random
import requests

from bs4 import BeautifulSoup

LOG = logging.getLogger("action")

def getAllActions():
"""
Expand Down Expand Up @@ -350,7 +352,8 @@ def marvinSun(row):
msg = getString("sun", "msg").format(sunrise, sunset)
return msg

except Exception:
except Exception as e:
LOG.error("Failed to get sun times: %s", e)
return getString("sun", "error")

return msg
Expand All @@ -371,7 +374,8 @@ def marvinWeather(row):
soup.h4.findNextSibling("p").text
)

except Exception:
except Exception as e:
LOG.error("Failed to get weather: %s", e)
msg = getString("smhi", "failed")

return msg
Expand Down Expand Up @@ -485,7 +489,8 @@ def marvinBirthday(row):
else:
msg = getString("birthday", "somebody").format(my_strings)

except Exception:
except Exception as e:
LOG.error("Failed to get birthday: %s", e)
msg = getString("birthday", "error")

return msg
Expand All @@ -507,7 +512,8 @@ def marvinNameday(row):
msg = getString("nameday", "somebody").format(",".join(names))
else:
msg = getString("nameday", "nobody")
except Exception:
except Exception as e:
LOG.error("Failed to get nameday: %s", e)
msg = getString("nameday", "error")
return msg

Expand Down Expand Up @@ -553,7 +559,8 @@ def getJoke():
r = requests.get(url, timeout=5)
joke_data = r.json()
return joke_data["value"]
except Exception:
except Exception as e:
LOG.error("Failed to get joke: %s", e)
return getString("joke", "error")

def marvinJoke(row):
Expand All @@ -575,7 +582,8 @@ def getCommit():
res = r.text.strip()
msg = f"Använd detta meddelandet: '{res}'"
return msg
except Exception:
except Exception as e:
LOG.error("Failed to get commit message: %s", e)
return getString("commit", "error")

def marvinCommit(row):
Expand Down

0 comments on commit e438975

Please sign in to comment.