From 107e57c41b658951869a11ab009ee3ad8305ffcc Mon Sep 17 00:00:00 2001 From: dgw Date: Sun, 13 Oct 2024 11:20:21 -0500 Subject: [PATCH] Backport invalid value logging in `ChoiceAttribute` from #2624 to 8.0.x --- sopel/config/types.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/sopel/config/types.py b/sopel/config/types.py index 73f7a8b33..569995eca 100644 --- a/sopel/config/types.py +++ b/sopel/config/types.py @@ -649,7 +649,10 @@ def parse(self, value): if value in self.choices: return value else: - raise ValueError('Value must be in {}'.format(self.choices)) + raise ValueError( + '{!r} is not one of the valid choices: {}' + .format(value, ', '.join(self.choices)) + ) def serialize(self, value): """Make sure ``value`` is valid and safe to write in the config file. @@ -662,7 +665,10 @@ def serialize(self, value): if value in self.choices: return value else: - raise ValueError('Value must be in {}'.format(self.choices)) + raise ValueError( + '{!r} is not one of the valid choices: {}' + .format(value, ', '.join(self.choices)) + ) class FilenameAttribute(BaseValidated):