pyteal icon indicating copy to clipboard operation
pyteal copied to clipboard

Pass message or error code with assertions

Open kashishkhullar opened this issue 3 years ago • 3 comments

Problem

Currently we have a complicated process to find the reason for an assertion failure. It would be great if the assertions can return a error message or if we have size limitation, a specific error byte and return it on assert failure.

Solution

Send a direct message to caller

Assert( <condition>,  Bytes("failure reason"))

OR Send a number or byte that can be mapped to a error message

Assert(<condition>, Int(123))

kashishkhullar avatar Jul 10 '22 21:07 kashishkhullar

I would love to work on this issue, is a problem that I am facing too while I am debugging the pyteal contracts.

ernestosperanza avatar Aug 08 '22 12:08 ernestosperanza

@ernestosperanza See https://github.com/algorand/pyteal/pull/410 that allows comments to be added to expressions and the source map feature of the algod can be used to map back to the teal source line.

Unfortunately the comments are currently added to the top of the expression that assert evaluates so it wouldn't be trivial to spit out the comment @ the assert exactly but I'd like it to.

barnjamin avatar Aug 08 '22 12:08 barnjamin

@barnjamin I dont know how to move forward with it, maybe it's complex for my skill. I would look up a simpler issue

ernestosperanza avatar Aug 09 '22 01:08 ernestosperanza