Skip to content

Commit

Permalink
print EvalError in a slightly more user friendly way
Browse files Browse the repository at this point in the history
  • Loading branch information
arvidn committed Jul 9, 2024
1 parent dfe8cdd commit eeb8053
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions wheel/python/clvm_rs/eval_error.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
from .ser import sexp_to_bytes

class EvalError(ValueError):
def __init__(self, message: str, sexp):
super().__init__(message)
self._sexp = sexp

def __str__(self) -> str:
return f"({self.args[0]}, {sexp_to_bytes(self._sexp).hex()})"
12 changes: 12 additions & 0 deletions wheel/python/tests/test_program.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,3 +493,15 @@ def test_tree_hash_no_caching(self):
self.assertEqual(p3p._cached_sha256_treehash.hex(), eh3)
self.assertEqual(p._cached_sha256_treehash.hex(), eh)
self.assertEqual(p2._cached_sha256_treehash.hex(), eh2)

def test_repr() -> None:
temp = Program.to([8, (1, "foo")])
assert f"{temp}" == "ff08ffff0183666f6f80"

Program.set_run_unsafe_max_cost(11000000000)

try:
temp.run([])
assert False
except EvalError as e:
assert f"{e}" == "(clvm raise, 83666f6f)"

0 comments on commit eeb8053

Please sign in to comment.