Skip to content

Commit

Permalink
Merge pull request #2624 from sopel-irc/ChoiceAttribute-log-invalid-v…
Browse files Browse the repository at this point in the history
…alue

config.types.ChoiceAttribute: log the invalid value if validation fails
  • Loading branch information
dgw authored Oct 13, 2024
2 parents dcb9eec + 7a2346b commit f3d3704
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions sopel/config/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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):
Expand Down

0 comments on commit f3d3704

Please sign in to comment.