HeliosLang/compiler

Extend UserError to include Args

Closed this issue · 1 comments

Just wondering if you'd be open to adding in the args (CBOR Encoded) into an Attribute of UserError when thrown?

Change would be in TxWitness::executeRedeemer; something like:

if (profile.result instanceof UserError) {
  profile.result.args = encodeArgs(args);
  throw profile.result;
} else {

The encodeArgs would just loop thru the 3 Array entries converting the UplcDataValue into CBOR Hex.
Again something like:

function encodeArgs(args) {
 return [
   bytesToHex(args[0].data.toCbor()),
   bytesToHex(args[1].data.toCbor()),
   bytesToHex(args[2].data.toCbor())
 ]
}

This would be useful for integration testing / validation as we can then take the 'args' and provide them into a run with a verion of the contract compiled without removing 'print' and 'trace' statements.

v0.13.37 adds a context property to UserError, which is filled with Datum, Redeemer and ScriptContext for validator scripts throwing an error, and Redeemer and ScriptContext for minting scripts throwing an error.

Eg. error.context.Datum: string