From 17c907ecc7e388472360ec7208cbfddf5d957fdc Mon Sep 17 00:00:00 2001 From: Sergei Maertens Date: Tue, 18 Jun 2024 12:31:57 +0200 Subject: [PATCH] :recycle: Clean up InvalidPluginConfiguration interface Added explicit message parameter that can be accessed, instead of having to rely on exc.args[0] which *could* be empty. Now you must instantiate this exception with a message argument. The message is still forwarded to the parent exception in case other usages still rely on exc.args[0], but this will be refactored later. --- src/openforms/contrib/brk/service.py | 6 +++--- src/openforms/contrib/kadaster/service.py | 6 +++--- src/openforms/plugins/exceptions.py | 4 +++- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/openforms/contrib/brk/service.py b/src/openforms/contrib/brk/service.py index 2d1d49056f..4f0f2557fc 100644 --- a/src/openforms/contrib/brk/service.py +++ b/src/openforms/contrib/brk/service.py @@ -1,4 +1,4 @@ -from openforms.forms.models.form import Form +from openforms.forms.models import Form from openforms.plugins.exceptions import InvalidPluginConfiguration from .checks import BRKValidatorCheck @@ -10,7 +10,7 @@ def check_brk_config_for_addressNL() -> str: if any(form.has_component("addressNL") for form in live_forms): try: BRKValidatorCheck.check_config() - except InvalidPluginConfiguration as e: - return e.args[0] + except InvalidPluginConfiguration as exc: + return exc.message return "" diff --git a/src/openforms/contrib/kadaster/service.py b/src/openforms/contrib/kadaster/service.py index 4fbd5489ab..3becf8512e 100644 --- a/src/openforms/contrib/kadaster/service.py +++ b/src/openforms/contrib/kadaster/service.py @@ -1,5 +1,5 @@ from openforms.contrib.kadaster.config_check import BAGCheck -from openforms.forms.models.form import Form +from openforms.forms.models import Form from openforms.plugins.exceptions import InvalidPluginConfiguration @@ -20,7 +20,7 @@ def check_bag_config_for_address_fields() -> str: try: BAGCheck.check_config() - except InvalidPluginConfiguration as e: - return e.args[0] + except InvalidPluginConfiguration as exc: + return exc.message return "" diff --git a/src/openforms/plugins/exceptions.py b/src/openforms/plugins/exceptions.py index d00f43a8db..29cdd709c4 100644 --- a/src/openforms/plugins/exceptions.py +++ b/src/openforms/plugins/exceptions.py @@ -1,5 +1,7 @@ class InvalidPluginConfiguration(Exception): - pass + def __init__(self, message: str, *args, **kwargs): + self.message = message + super().__init__(message, *args, **kwargs) class PluginNotEnabled(Exception):