-
Notifications
You must be signed in to change notification settings - Fork 309
Improve errors #270
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
Improve errors #270
Conversation
See https://github.com/pydantic/pydantic-core/blob/main/src/errors/kinds.rs
|
Thanks so much for this, hope that helps. If you have more questions, LMK. I'll be back at a computer on Monday so can explain more fully then if they're still not clear. |
I had a go at adding it. I have a feeling it is either in pretty good shape or couldn't be further from correct, I'm just not sure which it is 😄 Either way I'm happy to make any updates. |
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #270 +/- ##
==========================================
- Coverage 98.61% 97.80% -0.81%
==========================================
Files 51 51
Lines 5342 5388 +46
Branches 39 39
==========================================
+ Hits 5268 5270 +2
- Misses 74 118 +44
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests need adding too.
Let me know if you need help with the remaining bits?
pydantic_core/_pydantic_core.pyi
Outdated
|
||
class PydanticErrorKind(ValueError): | ||
kind: str | ||
contect: 'dict[str, str | int] | None' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
contect: 'dict[str, str | int] | None' | |
context: 'dict[str, str | int] | None' |
also needs an __init__
method.
src/errors/kinds.rs
Outdated
} | ||
} | ||
|
||
#[pyclass(extends=PyValueError, module="pydantic_core._pydantic_core")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be moved to value_exception.rs
.
src/errors/kinds.rs
Outdated
#[derive(Debug, Clone)] | ||
pub struct PydanticErrorKind { | ||
kind: String, | ||
message_template: String, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
message_template: String, | |
message_template: String, |
This isn't required.
The whole idea of PydanticErrorKind
is that message_template
is taken from ErrorKind
.
This is what I meant, a bit of macro fu required, but otherwise I think quite clear. @sanders41 are you okay finishing this off, or would you like me to?
|
Thanks for getting me unstuck here! Seeing what you did it makes sense now. I can work on finishing off the rest of it. |
Sorry for the delay with getting back to this. One thing I noticed in testing is when an Also when trying to merge main to resolve the conflicts it looks like |
I think that's fine, we should give every error itsy own |
@sanders41 any idea when this might be completed? I'll wait to merge #282 until this is merged to avoid more conflicts. |
I was waiting to hear back about resolving the merge conflict. I have one conflict on an import of |
It's generally up to the PR author to resolve conflicts. In this case |
Yes, I planned to resolve it. I just wanted to make sure I resolved it in the correct direction because looking at main it looked like it could be possibly the other way around 😄 . I can resolve this today. |
great, thanks so much. |
Ha, I'm an idiot...of course that is the way to resolve it, I renamed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looking good, we need some tests of using PydanticErrorKind
inside validation functions and confirming the correct ValidationError
is raised.
thanks so much for this. |
Closes #267
For this part I wasn't clear on what is needed. Does this literally mean create a new error type called
PydanticErrorKind
? And for "use an existing error kind" I assume you have a specific one to use in mind?