Skip to content

Commit

Permalink
adapter.json.json_deserialization: handle AASConstraintViolation
Browse files Browse the repository at this point in the history
Previously, `AASConstraintViolation` exception weren't excepted in the
json deserialization, breaking failsafe parsing whenever a constraint is
violated. This commit ports edf5f27 to
the json deserialization.
  • Loading branch information
jkhsjdhjs authored and s-heppner committed Oct 3, 2023
1 parent d96c605 commit 9e8d46c
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions basyx/aas/adapter/json/json_deserialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def object_hook(cls, dct: Dict[str, object]) -> object:
# Use constructor function to transform JSON representation into BaSyx Python SDK model object
try:
return AAS_CLASS_PARSERS[model_type](dct)
except (KeyError, TypeError) as e:
except (KeyError, TypeError, model.AASConstraintViolation) as e:
error_message = "Error while trying to convert JSON object into {}: {} >>> {}".format(
model_type, e, pprint.pformat(dct, depth=2, width=2**14, compact=True))
if cls.failsafe:
Expand All @@ -217,7 +217,7 @@ def object_hook(cls, dct: Dict[str, object]) -> object:
# constructors for complex objects will skip those items by using _expect_type().
return dct
else:
raise type(e)(error_message) from e
raise (type(e) if isinstance(e, (KeyError, TypeError)) else TypeError)(error_message) from e

# ##################################################################################################
# Utility Methods used in constructor methods to add general attributes (from abstract base classes)
Expand Down

0 comments on commit 9e8d46c

Please sign in to comment.