From 5b235a01cbec8f43ffe18ee216a27a255529c7c9 Mon Sep 17 00:00:00 2001 From: Maximilian Haye Date: Thu, 22 Aug 2024 13:55:27 +0200 Subject: [PATCH] feat: give helpful error when worker class doesn't exist --- questionpy_server/settings.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/questionpy_server/settings.py b/questionpy_server/settings.py index 16cef0f..a1aac21 100644 --- a/questionpy_server/settings.py +++ b/questionpy_server/settings.py @@ -91,7 +91,13 @@ class WorkerSettings(BaseModel): @classmethod def _load_worker_class(cls, value: object) -> builtins.type[Worker]: if isinstance(value, str): - value = locate(value) + klass = locate(value) + + if klass is None: + msg = f"Could not locate class '{value}'" + raise TypeError(msg) + + value = klass if not isinstance(value, type) or not issubclass(value, Worker): msg = f"{value} is not a subclass of Worker"