Skip to content

Commit

Permalink
better logging for deserialization errors
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Horton <paul.horton@owasp.org>
  • Loading branch information
madpah committed Jan 27, 2023
1 parent 1f80c4b commit a77452d
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions serializable/__init__.py
Expand Up @@ -21,6 +21,7 @@
import inspect
import json
import logging
import os
import re
import typing # noqa: F401
import warnings
Expand Down Expand Up @@ -299,7 +300,10 @@ def _from_json(cls: Type[_T], data: Dict[str, Any]) -> object:
else:
_data[k] = prop_info.concrete_type(v)
except AttributeError as e:
logging.error(f'There was an AttributeError deserializing JSON to {cls} the Property {prop_info}: {e}')
logging.error(f'There was an AttributeError deserializing JSON to {cls}.{os.linesep}'
f'The Property is: {prop_info}{os.linesep}'
f'The Value was: {v}{os.linesep}'
f'Exception: {e}{os.linesep}')
raise AttributeError(
f'There was an AttributeError deserializing JSON to {cls} the Property {prop_info}: {e}'
)
Expand Down Expand Up @@ -560,7 +564,10 @@ def _from_xml(cls: Type[_T], data: Union[TextIOWrapper, ElementTree.Element],
else:
_data[decoded_k] = prop_info.concrete_type(child_e.text)
except AttributeError as e:
logging.error(f'There was an AttributeError deserializing XML to {cls} the Property {prop_info}: {e}')
logging.error(f'There was an AttributeError deserializing JSON to {cls}.{os.linesep}'
f'The Property is: {prop_info}{os.linesep}'
f'The Value was: {v}{os.linesep}'
f'Exception: {e}{os.linesep}')
raise AttributeError(
f'There was an AttributeError deserializing XML to {cls} the Property {prop_info}: {e}'
)
Expand Down

0 comments on commit a77452d

Please sign in to comment.