Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update error message for enum validator #673

Merged
merged 3 commits into from Jul 24, 2019

Conversation

dmontagu
Copy link
Collaborator

@dmontagu dmontagu commented Jul 17, 2019

Change Summary

Modify the EnumError message to be a little clearer (in line with the WrongConstantError).

Related issue number

#671

Checklist

  • Unit tests for the changes exist
  • Tests pass on CI and coverage remains at 100%
  • Documentation reflects the changes where applicable
  • HISTORY.rst has been updated
    • if this is the first change since a release, please add a new section
    • include the issue number or this pull request number #<number>
    • include your github username @<whomever>

'loc': ('tool',),
'msg': 'value is not a valid enumeration member; permitted: 1, 2',
'type': 'type_error.enum',
'ctx': {'enum_type': ToolEnum},
Copy link
Collaborator Author

@dmontagu dmontagu Jul 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

putting the type in the context (rather than the permitted values, as in WrongConstantError), means that the type is visible in the traceback for debugging purposes, while only the permitted values are visible in the error message (which may be served externally).

Copy link
Owner

@samuelcolvin samuelcolvin Jul 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense, the idea of ctx was something like "things you might need when rendering your own error message".

@codecov
Copy link

@codecov codecov bot commented Jul 17, 2019

Codecov Report

Merging #673 into master will not change coverage.
The diff coverage is 100%.

@@          Coverage Diff          @@
##           master   #673   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          15     15           
  Lines        2712   2716    +4     
  Branches      537    538    +1     
=====================================
+ Hits         2712   2716    +4

@samuelcolvin
Copy link
Owner

@samuelcolvin samuelcolvin commented Jul 19, 2019

LGTM, will merge when I get this far through 😓

@@ -217,9 +217,10 @@ def set_validator(v: Any) -> Set[Any]:


def enum_validator(v: Any, field: 'Field', config: 'BaseConfig') -> Enum:
with change_exception(errors.EnumError, ValueError):
Copy link
Contributor

@Bobronium Bobronium Jul 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't just add kwargs support to context manager?
and then:

with change_exception(errors.EnumError, ValueError, enum_type=field.type_):
    ...

Copy link
Collaborator Author

@dmontagu dmontagu Jul 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing that would be better placed in a separate PR; not sure it would be worth it if it was only used in this instance. But I haven't looked to see if it could simplify the error handling anywhere else.

@samuelcolvin samuelcolvin merged commit b702eb8 into samuelcolvin:master Jul 24, 2019
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants