-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Error context and message #183
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
Changes from 1 commit
c1110f0
8a25c51
b14c7bd
f8e4478
9692994
15cd4e1
ed6d84e
9e2ed7f
6447783
01a20e5
ecb2ecc
a2cc0a9
ef07e61
04d72e9
bc3bed8
a677a7e
89804fb
9e82397
6c2da85
45f49c1
95b710f
af3d24f
c5c906e
6e62458
9b726ee
446cc76
81df1c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
errors.py module; Change errors interface a…
… bit
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| __all__ = ( | ||
| 'PydanticErrorMixin', | ||
| 'PydanticTypeError', | ||
| 'PydanticValueError', | ||
|
|
||
| 'ConfigError', | ||
|
|
||
| 'MissingError', | ||
| 'ExtraError', | ||
|
|
||
| 'DecimalError', | ||
| 'DecimalIsNotFiniteError', | ||
| 'DecimalMaxDigitsError', | ||
| 'DecimalMaxPlacesError', | ||
| 'DecimalWholeDigitsError', | ||
|
|
||
| 'UUIDError', | ||
| 'UUIDVersionError', | ||
| ) | ||
|
|
||
|
|
||
| class PydanticErrorMixin: | ||
| msg_template: str | ||
|
|
||
| def __init__(self, **ctx): | ||
| self.ctx = ctx or None | ||
|
|
||
| def __str__(self) -> str: | ||
| return self.msg_template.format(**self.ctx or {}) | ||
|
|
||
|
|
||
| class PydanticTypeError(PydanticErrorMixin, | ||
|
||
| TypeError): | ||
| pass | ||
|
|
||
|
|
||
| class PydanticValueError(PydanticErrorMixin, | ||
| ValueError): | ||
| pass | ||
|
|
||
|
|
||
| class ConfigError(RuntimeError): | ||
| pass | ||
|
|
||
|
|
||
| class MissingError(PydanticValueError): | ||
| msg_template = 'field required' | ||
|
|
||
|
|
||
| class ExtraError(PydanticValueError): | ||
| msg_template = 'extra fields not permitted' | ||
|
|
||
|
|
||
| class DecimalError(PydanticTypeError): | ||
| msg_template = 'value is not a valid decimal' | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. from gitter you said
You're right, that's not ok, so the other decimal related exceptions below can't inherit from this However we want the end The way to do this is to add class DecimalIsNotFiniteError(PydanticValueError):
display_name = 'decimal.not_finite_error'Then in name = getattr(b, 'display_name', None) or b.__name__
yield name.replace('Error', '')does that make sense?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we want to introduce And we can remove
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree except that But maybe best for you to implement it and see how you go. |
||
|
|
||
|
|
||
| class DecimalIsNotFiniteError(PydanticValueError): | ||
| msg_template = 'value is not a valid decimal' | ||
|
|
||
|
|
||
| class DecimalMaxDigitsError(PydanticValueError): | ||
| msg_template = 'ensure that there are no more than {max_digits} digits in total' | ||
|
|
||
| def __init__(self, *, max_digits: int) -> None: | ||
| super().__init__(max_digits=max_digits) | ||
|
|
||
|
|
||
| class DecimalMaxPlacesError(PydanticValueError): | ||
| msg_template = 'ensure that there are no more than {decimal_places} decimal places' | ||
|
|
||
| def __init__(self, *, decimal_places: int) -> None: | ||
| super().__init__(decimal_places=decimal_places) | ||
|
|
||
|
|
||
| class DecimalWholeDigitsError(PydanticValueError): | ||
| msg_template = 'ensure that there are no more than {whole_digits} digits before the decimal point' | ||
|
|
||
| def __init__(self, *, whole_digits: int) -> None: | ||
| super().__init__(whole_digits=whole_digits) | ||
|
|
||
|
|
||
| class UUIDError(PydanticTypeError): | ||
| msg_template = 'value is not a valid uuid' | ||
|
|
||
|
|
||
| class UUIDVersionError(PydanticValueError): | ||
| msg_template = 'uuid version {required_version} expected' | ||
|
|
||
| def __init__(self, *, required_version: int) -> None: | ||
| super().__init__(required_version=required_version) | ||
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.
I think this will lead to problems when people (eg. me) add errors and forget to update
__all__, let's remove__all__.If we're really worried about exposing
Decimaletc. we could even import them asfrom decimal import Decimal as _Decimal, but I don't think it's necessary.