Skip to content
This repository has been archived by the owner on Apr 10, 2023. It is now read-only.

Commit

Permalink
Completely rework error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
rossmacarthur committed Feb 10, 2020
1 parent 26963d6 commit c95b6b3
Show file tree
Hide file tree
Showing 16 changed files with 624 additions and 1,191 deletions.
17 changes: 8 additions & 9 deletions README.rst
Expand Up @@ -114,15 +114,15 @@ access the values on the model instance.
>>> user.email
'torvalds@linuxfoundation.org'
Models are validated when they are instantiated and an ``InstantiationError`` is
Models are validated when they are instantiated and a ``ValidationError`` is
raised if you provide invalid values.

.. code-block:: python
>>> User(name='Linus Torvalds', email='not an email')
Traceback (most recent call last):
...
serde.exceptions.InstantiationError: 'not an email' is not a valid email
serde.exceptions.ValidationError: {'email': 'invalid email'}
Models are serialized into primitive Python types using the ``to_dict()`` method
on the model instance.
Expand Down Expand Up @@ -158,15 +158,14 @@ Or from JSON using the ``from_json()`` method.
... "email": "noreply@stanford.edu"
... }''')
Attempting to deserialize invalid data will result in a
``DeserializationError``.
Attempting to deserialize invalid data will result in a ``ValidationError``.

.. code-block:: python
>>> User.from_dict({'username': 'Donald Knuth'})
Traceback (most recent call last):
...
serde.exceptions.DeserializationError: expected field 'email'
serde.exceptions.ValidationError: {'email': "missing data, expected field 'email'"}
Models
------
Expand Down Expand Up @@ -304,19 +303,19 @@ to use for the deserialization.
>>> milo.hates_cats
False
An invalid or missing tag will raise a ``DeserializationError``.
An invalid or missing tag will raise a ``ValidationError``.

.. code-block:: python
>>> Pet.from_dict({'name': 'Milo', 'hates_cats': False})
Traceback (most recent call last):
...
serde.exceptions.DeserializationError: expected tag 'species'
serde.exceptions.ValidationError: missing data, expected tag 'species'
>>>
>>> Pet.from_dict({'name': 'Duke', 'species': '__main__.Horse'})
Traceback (most recent call last):
...
serde.exceptions.DeserializationError: no variant found for tag '__main__.Horse'
serde.exceptions.ValidationError: no variant found
Externally tagged
^^^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -377,7 +376,7 @@ won't be included in the variant list during deserialization.
>>> Fruit()
Traceback (most recent call last):
...
serde.exceptions.InstantiationError: unable to instantiate abstract Model 'Fruit'
TypeError: unable to instantiate abstract model 'Fruit'
Custom tags
^^^^^^^^^^^
Expand Down
1 change: 1 addition & 0 deletions RELEASES.rst
Expand Up @@ -6,6 +6,7 @@ Releases

*Unreleased*

- Completely rework error handling.
- Make ``Tag.lookup_tag`` default to module + qualname.

0.7.3
Expand Down
10 changes: 2 additions & 8 deletions docs/api.rst
Expand Up @@ -93,12 +93,6 @@ Exceptions

.. automodule:: serde.exceptions

.. autoexception:: serde.exceptions.SerdeError
:members: iter_contexts, pretty

.. autoexception:: serde.exceptions.SerializationError
.. autoexception:: serde.exceptions.DeserializationError
.. autoexception:: serde.exceptions.InstantiationError
.. autoexception:: serde.exceptions.NormalizationError
.. autoexception:: serde.exceptions.ValidationError
.. autoexception:: serde.exceptions.ContextError
.. autoexception:: serde.exceptions.MissingDependency
.. autoexception:: serde.exceptions.ValidationError
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -43,7 +43,7 @@ def get_metadata():
metadata = get_metadata()

# Primary requirements
install_requires = ['isodate==0.6.*', 'six==1.*']
install_requires = ['isodate==0.6.*', 'six==1.*,>=1.13.0']
ext_requires = ['chardet==3.*', 'validators>=0.12.0,<0.15.0']

setup(
Expand Down
3 changes: 2 additions & 1 deletion src/serde/__init__.py
Expand Up @@ -3,10 +3,11 @@
deserializing, and validating data structures in Python.
"""

from serde.exceptions import ValidationError
from serde.model import Model


__all__ = ['Model', 'exceptions', 'fields', 'tags', 'validators']
__all__ = ['Model', 'ValidationError', 'fields', 'tags', 'validators']
__title__ = 'serde'
__version__ = '0.7.3'
__url__ = 'https://github.com/rossmacarthur/serde'
Expand Down

0 comments on commit c95b6b3

Please sign in to comment.