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

reuse error kinds where appropriate #81

Merged
merged 8 commits into from
Jun 20, 2022

Conversation

czotomo
Copy link
Contributor

@czotomo czotomo commented Jun 10, 2022

fixes: #76

@@ -118,6 +102,16 @@ pub enum ErrorKind {
LiteralSingleError,
#[strum(serialize = "literal_error", message = "Value must be one of: {expected}")]
LiteralMultipleError,
// ---------------------
// comparison errors
Copy link
Contributor Author

Choose a reason for hiding this comment

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

What I was considering, in addition to the changes present, is whether min/max length errors should get aggregated?
This would require passing the involved Py type's name or removing this information from the error message.
@samuelcolvin thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

Not quite sure what you mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Apologies, I made this sentence unnecessarily unreadable.
What I meant is I wondered whether, say, DictTooShort and ListTooShort errors should become one, too, just like the comparison errors did in this very PR.

Copy link
Member

Choose a reason for hiding this comment

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

Yes I guess so, but it'll require a context variable for "items" vs. "characters" etc.

Note, I'll also started some of these changes in #77.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, alright, I didn't realise. I guess we can close this one then :D

Copy link
Member

Choose a reason for hiding this comment

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

#77 is now merged.

@codecov
Copy link

codecov bot commented Jun 10, 2022

Codecov Report

Merging #81 (26fd32d) into main (fc26fb4) will not change coverage.
The diff coverage is 66.66%.

@@           Coverage Diff           @@
##             main      #81   +/-   ##
=======================================
  Coverage   93.78%   93.78%           
=======================================
  Files          40       40           
  Lines        3491     3491           
  Branches       26       26           
=======================================
  Hits         3274     3274           
  Misses        217      217           
Impacted Files Coverage Δ
src/errors/kinds.rs 100.00% <ø> (ø)
src/validators/dict.rs 77.90% <0.00%> (ø)
src/validators/list.rs 78.48% <0.00%> (ø)
src/validators/float.rs 98.44% <100.00%> (ø)
src/validators/int.rs 98.44% <100.00%> (ø)
src/validators/set.rs 97.46% <100.00%> (ø)
src/validators/tuple.rs 97.35% <100.00%> (ø)
src/validators/optional.rs
src/validators/nullable.rs 100.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fc26fb4...26fd32d. Read the comment docs.

@czotomo czotomo closed this Jun 11, 2022
@czotomo czotomo reopened this Jun 14, 2022
@czotomo czotomo marked this pull request as draft June 15, 2022 20:46
@czotomo czotomo changed the title gather comparison errors under unified enumerations reuse error kinds where appropriate Jun 16, 2022
@czotomo czotomo marked this pull request as ready for review June 16, 2022 22:51
'loc': [],
'message': 'String must have at most 5 characters',
'input_value': '12345x',
'context': {'max_length': 5},
'context': {'type': 'String', 'max_length': 5, 'element_name': 'characters'},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@samuelcolvin I am not sure if this 'element_name' (I fully expect you to not like that context variable and ask me to rename it :D) should be printed out. It's kinda redundant? Same goes for the type in this context, I guess. It's all explicit in the error's message anyway.

Copy link
Member

Choose a reason for hiding this comment

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

Let's keep string (and maybe bytes) as separate enum members, but with the same output value via serialize.

Then we only need type which is fine.

Copy link
Member

Choose a reason for hiding this comment

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

Part of the point of context is to allow translation of errors in downstream packages.

So type should be included.

@samuelcolvin samuelcolvin merged commit 8faeed7 into pydantic:main Jun 20, 2022
@samuelcolvin
Copy link
Member

Thanks so much.

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.

reuse error kinds where appropriate
2 participants