metaplex-foundation/amman

Not obvious that you need a cusper error resolver to assertError

stegaBOB opened this issue · 2 comments

When you call assertError on a transactionHandler with no errorResolver and include a typed error generated by Solita, you get a relatively unhelpful error message: not ok 39 Expected an error of type TreasuryIsNotEmptyError, but did not get a typed error. Got: 'custom program error: 0x178a' in the logs instead

TS Code with no error resolver:

await transactionHandler
  .sendAndConfirmTransaction(buyTx, [payer])
  .assertError(t, GatingTokenMissingError);

Potentially good error:

Error: Expected an error of type GatingTokenMissingError, but did not get a typed error. Got: 'custom program error: 0x1794' in the logs instead.
Note: your TransactionHandler does not include an errorResolver. Try using a cusper error resolver as shown here: https://github.com/thlorenz/tictactoe/pull/10

Actual error:

Error: Expected an error of type GatingTokenMissingError, but did not get a typed error. Got: 'custom program error: 0x1794' in the logs instead

Yes, that's correct. When you call assertError on a transactionHandler with no errorResolver and include a typed error generated by Solita, you will get a relatively unhelpful error message. This is because the errorResolver is responsible for mapping the custom program error code to a typed error that can be recognized by the assertError function. Without the errorResolver, the assertError function will not be able to recognize the custom program error code and will simply display the raw error message. Therefore, it's important to include an errorResolver when calling assertError with a typed error generated by Solita.