Skip to content

Commit

Permalink
refactor: Output a more useful error message when deserialization fails
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanmenzel committed Sep 19, 2024
1 parent 738a008 commit 91c7ca3
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/puya/awst/serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
from collections.abc import Mapping

import cattrs
from cattrs import ClassValidationError, IterableValidationError, transform_error
from cattrs.preconf.json import make_converter
from cattrs.strategies import configure_tagged_union, include_subclasses
from immutabledict import immutabledict

from puya.awst import nodes, txn_fields, wtypes
from puya.errors import InternalError
from puya.utils import StableSet


Expand Down Expand Up @@ -86,4 +88,7 @@ def awst_to_json(awst: nodes.AWST) -> str:


def awst_from_json(json: str) -> nodes.AWST:
return _get_converter().loads(json, nodes.AWST) # type: ignore[type-abstract]
try:
return _get_converter().loads(json, nodes.AWST) # type: ignore[type-abstract]
except (ClassValidationError, IterableValidationError, BaseException) as err:
raise InternalError("Deserialization error: \n" + "\n".join(transform_error(err))) from err

0 comments on commit 91c7ca3

Please sign in to comment.