From 5a0faa2bccf9cdec1bb57f0c11f632679538ebc3 Mon Sep 17 00:00:00 2001 From: Nakidai Date: Fri, 1 Nov 2024 02:47:03 +0300 Subject: 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. --- src/petthecord/cache.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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) -- cgit 1.4.1