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

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},

This comment has been minimized.

Copy link
@dmontagu

dmontagu Jul 17, 2019

Author Collaborator

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).

This comment has been minimized.

Copy link
@samuelcolvin

samuelcolvin Jul 19, 2019

Owner

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

@codecov

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link
Owner

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):

This comment has been minimized.

Copy link
@MrMrRobat

MrMrRobat Jul 19, 2019

Contributor

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

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

This comment has been minimized.

Copy link
@dmontagu

dmontagu Jul 19, 2019

Author Collaborator

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.

@dmontagu dmontagu force-pushed the dmontagu:enum_error_msg branch from 03dbf92 to 1acd97a Jul 23, 2019

David Montague and others added some commits Jul 17, 2019

David Montague

@samuelcolvin samuelcolvin merged commit b702eb8 into samuelcolvin:master Jul 24, 2019

6 of 9 checks passed

Header rules No header rules processed
Details
Pages changed 2 new files uploaded
Details
Redirect rules No redirect rules processed
Details
Mixed content No mixed content detected
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
deploy/netlify Deploy preview ready!
Details
samuelcolvin.pydantic Build #20190724.9 succeeded
Details
samuelcolvin.pydantic (Job Python36) Job Python36 succeeded
Details
samuelcolvin.pydantic (Job Python37) Job Python37 succeeded
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.