From 9c96f4f3c9a710ef4cc4b4d9c44c9573483af9e0 Mon Sep 17 00:00:00 2001 From: Piotr Gaczkowski Date: Sun, 5 Nov 2023 22:43:19 +0100 Subject: [PATCH] Add exception logging --- Dockerfile | 2 +- bot.py | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index df91358..d83d571 100644 --- a/Dockerfile +++ b/Dockerfile @@ -26,4 +26,4 @@ COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt COPY *.py . -CMD ["python", "bot.py"] +CMD ["python", "bot.py", "--log=WARNING"] diff --git a/bot.py b/bot.py index 9f6a607..53b0414 100644 --- a/bot.py +++ b/bot.py @@ -68,11 +68,14 @@ async def on_ready(): """ print(fields) try: - os.makedirs(directory) + os.makedirs(directory, mode=0o777, exist_ok=True) except FileExistsError: - pass - with open(f"{directory}/{filename}", "w") as f: - f.write(fields) + logging.exception("We can't create a tree. Why, oh why?") + try: + with open(f"{directory}/{filename}", "w") as f: + f.write(fields) + except PermissionError: + logging.exception("Oops, we can't write here!") logging.info( f"Guilds processed: {guilds_processed}, guilds total: {guilds_total}" )