algorand / pyteal

Algorand Smart Contracts in Python
https://pyteal.readthedocs.io
MIT License
285 stars 131 forks source link

Pass message or error code with assertions #437

Open kashishkhullar opened 2 years ago

kashishkhullar commented 2 years ago

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))
ernestosperanza commented 2 years ago

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

barnjamin commented 2 years ago

@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.

ernestosperanza commented 2 years ago

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