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 authored and daniel-makerx committed Oct 4, 2024
1 parent e7f13d1 commit cc3646b
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/puya/awst/serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@
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 import log
from puya.awst import nodes, txn_fields, wtypes
from puya.utils import StableSet

logger = log.get_logger(__name__)


def _unstructure_optional_enum_literal(value: object) -> object:
if value is None:
Expand Down Expand Up @@ -86,4 +90,10 @@ 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) as err:
logger.debug("Deserialization error: \n" + "\n".join(transform_error(err)))
raise ValueError(
"Error during deserialization of AWST json. See debug log for details"
) from err

0 comments on commit cc3646b

Please sign in to comment.