Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supply better error messaging on Reverts #823

Closed
camsjams opened this issue Mar 13, 2023 · 3 comments · Fixed by #1895
Closed

Supply better error messaging on Reverts #823

camsjams opened this issue Mar 13, 2023 · 3 comments · Fixed by #1895
Assignees
Labels
chore Issue is a chore

Comments

@camsjams
Copy link
Contributor

camsjams commented Mar 13, 2023

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

@camsjams camsjams self-assigned this Mar 13, 2023
@camsjams camsjams changed the title Add custom errors to typegen Update Enum support to generate Enums in TypeScript Mar 14, 2023
@camsjams camsjams changed the title Update Enum support to generate Enums in TypeScript Use Enums to supply better error messaging on Reverts Mar 14, 2023
@camsjams camsjams removed their assignment Sep 11, 2023
@Torres-ssf Torres-ssf added chore Issue is a chore and removed refactor labels Dec 8, 2023
@Torres-ssf Torres-ssf self-assigned this Dec 8, 2023
@Torres-ssf Torres-ssf changed the title Use Enums to supply better error messaging on Reverts Supply better error messaging on Reverts Dec 8, 2023
@Torres-ssf Torres-ssf removed their assignment Dec 11, 2023
@Dhaiwat10 Dhaiwat10 self-assigned this Mar 5, 2024
@theausicist
Copy link
Contributor

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 #1836 (which has some more info on this particular issue).

@petertonysmith94
Copy link
Contributor

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 😄

@diyahir
Copy link

diyahir commented Mar 18, 2024

Also running into this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Issue is a chore
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants