Error Reference¶
- Handling Errors
- SQLAthanor Errors
- SQLAthanorError (from
ValueError
) - SQLAlchemySupportError (from
SQLAthanorError
) - InvalidFormatError (from
SQLAthanorError
) - SerializationError (from
SQLAthanorError
) - ValueSerializationError (from
SerializationError
) - SerializableAttributeError (from
SerializationError
) - MaximumNestingExceededError (from
SerializationError
) - UnsupportedSerializationError (from
SerializationError
) - DeserializationError (from
SQLAthanorError
) - CSVStructureError (from
DeserializationError
) - JSONParseError (from
DeserializationError
) - YAMLParseError (from
DeserializationError
) - DeserializableAttributeError (from
DeserializationError
) - ValueDeserializationError (from
DeserializationError
) - UnsupportedDeserializationError (from
DeserializationError
) - ExtraKeyError (from
DeserializationError
)
- SQLAthanorError (from
- SQLAthanor Warnings
Handling Errors¶
Stack Traces¶
Because SQLAthanor produces exceptions which inherit from the standard library, it leverages the same API for handling stack trace information. This means that it will be handled just like a normal exception in unit test frameworks, logging solutions, and other tools that might need that information.
Errors During Serialization¶
from sqlathanor.errors import SerializableAttributeError, \
UnsupportedSerializationError, MaximumNestingExceededError
# For a SQLAlchemy Model Class named "User" and a model instance named "user".
try:
as_csv = user.to_csv()
as_json = user.to_json()
as_yaml = user.to_yaml()
as_dict = user.to_dict()
except SerializableAttributeError as error:
# Handle the situation where "User" model class does not have any attributes
# serializable to JSON.
pass
except UnsupportedSerializationError as error:
# Handle the situation where one of the "User" model attributes is of a data
# type that does not support serialization.
pass
except MaximumNestingExceededError as error:
# Handle a situation where "user.to_json()" received max_nesting less than
# current_nesting.
#
# This situation is typically an error on the programmer's part, since
# SQLAthanor by default avoids this kind of situation.
#
# Best practice is simply to let this exception bubble up.
raise error
Errors During De-Serialization¶
from sqlathanor.errors import DeserializableAttributeError, \
CSVStructureError, DeserializationError, ValueDeserializationError, \
ExtraKeysError, UnsupportedDeserializationError
# For a SQLAlchemy Model Class named "User" and a model instance named "user",
# with serialized data in "as_csv", "as_json", "as_yaml", and "as_dict" respectively.
try:
user.update_from_csv(as_csv)
user.update_from_json(as_json)
user.update_from_yaml(as_yaml)
user.update_from_dict(as_dict)
new_user = User.new_from_csv(as_csv)
new_user = User.new_from_json(as_json)
new_user = User.new_from_yaml(as_yaml)
new_user = User.new_from_dict(as_dict)
except DeserializableAttributeError as error:
# Handle the situation where "User" model class does not have any attributes
# de-serializable from the given format (CSV, JSON, YAML, or dict).
pass
except DeserializationError as error:
# Handle the situation where the serialized object ("as_csv", "as_json",
# "as_yaml", "as_dict") cannot be parsed, for example because it is not
# valid JSON, YAML, or dict.
pass
except CSVStructureError as error:
# Handle the situation where the structure of "as_csv" does not match the
# expectation configured for the "User" model class.
raise error
except ExtraKeysError as error:
# Handle the situation where the serialized object ("as_json",
# "as_yaml", "as_dict") may have unexpected keys/attributes and
# the error_on_extra_keys argument is False.
#
# Applies to: *_from_json(), *_from_yaml(), and *_from_dict() methods
pass
except ValueDeserializationError as error:
# Handle the situation where an input value in the serialized object
# raises an exception in the deserialization post-processing function.
pass
except UnsupportedDeserializationError as error:
# Handle the situation where the de-serialization process attempts to
# assign a value to an attribute that does not support de-serialization.
pass
SQLAthanor Errors¶
SQLAthanorError (from ValueError
)¶
-
class
SQLAthanorError
[source]¶ Base error raised by SQLAthanor. Inherits from
ValueError
.