From 9ee53041b6dcd678db083873654884ada1818445 Mon Sep 17 00:00:00 2001 From: lilydjwg Date: Fri, 12 Aug 2022 13:40:33 +0800 Subject: [PATCH] catch exceptions from Worker.run --- nvchecker/core.py | 2 +- nvchecker/util.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/nvchecker/core.py b/nvchecker/core.py index 7130bd7..5373601 100644 --- a/nvchecker/core.py +++ b/nvchecker/core.py @@ -259,7 +259,7 @@ class Dispatcher: func = mod.get_version ctx.run(worker.initialize, func) - ret.append(ctx.run(worker.run)) + ret.append(ctx.run(worker._run_maynot_raise)) return ret diff --git a/nvchecker/util.py b/nvchecker/util.py index 084da0a..85b65e7 100644 --- a/nvchecker/util.py +++ b/nvchecker/util.py @@ -146,6 +146,13 @@ class BaseWorker: '''Run the `tasks`. Subclasses should implement this method.''' raise NotImplementedError + async def _run_maynot_raise(self) -> None: + try: + await self.run() + except Exception: + # don't let an exception tear down the whole process + logger.exception('exception raised by Worker.run') + class AsyncCache: '''A cache for use with async functions.''' cache: Dict[Hashable, Any]