fuels-ts
fuels-ts copied to clipboard
Supply better error messaging on Reverts
Motivation
A Sway program can define and throw custom error types that are also sent back to caller app (in this case the TS-SDK), it would be useful to generate and map these to custom error objects in JS
Usage example
Temporary basic premise
pub enum InputError {
PriceCantBeZero: (),
}
impl SomeContract for Contract {
fn validate_inputs(token_id: u64, price: u64) {
require(price != 0, InputError::PriceCantBeZero);
}
}
class PriceCantBeZeroInputError extends Error {
}
Possible implementations
hook into revert FAILED_REQUIRE_SIGNAL and try to map out to an enum where applicable
Also review how a developer view logs.
Blocked by: #828 #829
is this being currently worked on? I have a solution (more a hack really) to allow for said custom errors. Can submit as a PR if an active solution isn't being built atm.
The custom error already exists within the logs
field which comes from (getDecodedLogs(callResult.receipts
), and is the ONLY item in logs[]
if there are not other "logged" values within the Sway contract (haven't tried this out yet). The decoded logs are already available, and require a slight modification to the code to allow for the custom revert reason as mentioned in this PR as well as https://github.com/FuelLabs/fuels-ts/issues/1836 (which has some more info on this particular issue).
Hey @theausicist 👋🏼
I believe @Dhaiwat10 is actively looking into this one, however, I'm sure it won't hurt to raise a PR if you have a solution already.
I would say that the issue #1836 is a duplicate of this one - so potentially worth closing in favour of #823 😄
Also running into this