about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNakidai <nakidai@disroot.org>2024-11-01 02:47:03 +0300
committerNakidai <nakidai@disroot.org>2024-11-01 02:47:03 +0300
commit5a0faa2bccf9cdec1bb57f0c11f632679538ebc3 (patch)
tree18a082e6e41ae6031ad8299676f8f55859f9f0b5
parent815382fe0c48a2fc2af1c256b3e52a9f3433e20a (diff)
downloadpetthecord-5a0faa2bccf9cdec1bb57f0c11f632679538ebc3.tar.gz
petthecord-5a0faa2bccf9cdec1bb57f0c11f632679538ebc3.zip
Suppress error on remove
When I was checking logs I've found that when ptc tries to update cache
because of new avatar the function raises an error about some
non-existent file:

    Traceback (most recent call last):
      File "/var/lib/ptc/venv/lib/python3.10/site-packages/aiohttp/web_protocol.py", line 462, in _handle_request
        resp = await request_handler(request)
      File "/var/lib/ptc/venv/lib/python3.10/site-packages/aiohttp/web_app.py", line 537, in _handle
        resp = await handler(request)
      File "/var/lib/ptc/venv/lib/python3.10/site-packages/petthecord/server.py", line 35, in petpet
        return Response(body=await self._petter.petpet(uid), content_type="image/gif")
      File "/var/lib/ptc/venv/lib/python3.10/site-packages/petthecord/cache.py", line 74, in petpet
        remove(path)
    FileNotFoundError: [Errno 2] No such file or directory: '/var/cache/petthecord/...gif'

Well, I think that it's OK to just suppress the error because GC still
will remove all unneeded files.
-rw-r--r--src/petthecord/cache.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/petthecord/cache.py b/src/petthecord/cache.py
index d111e99..aa5618d 100644
--- a/src/petthecord/cache.py
+++ b/src/petthecord/cache.py
@@ -71,7 +71,10 @@ class CachedPet:
             if (path := self._cache.get(user.id)) != str(avatar_path):
                 self._logger.debug("Generating new gif for {user.id}")
                 if path:
-                    remove(path)
+                    try:
+                        remove(path)
+                    except OSError:
+                        self._logger.warning("no {path} was found when replacing avatar")
                 self._cache[user.id] = str(avatar_path)
                 with open(self._path / "index.json", "w") as f:
                     dump(self._cache, f)