Skip to content

Commit

Permalink
♻️ Clean up InvalidPluginConfiguration interface
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sergei-maertens committed Jun 18, 2024
1 parent b946c10 commit 17c907e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/openforms/contrib/brk/service.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 ""
6 changes: 3 additions & 3 deletions src/openforms/contrib/kadaster/service.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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 ""
4 changes: 3 additions & 1 deletion src/openforms/plugins/exceptions.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down

0 comments on commit 17c907e

Please sign in to comment.