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

add error handler to cannon build process and all exported artifacts #31

Merged
merged 1 commit into from Sep 1, 2022

Conversation

dbeal-eth
Copy link
Contributor

@dbeal-eth dbeal-eth commented Sep 1, 2022

I have just pushed an advanced error handling/intercepting system in cannon. You can expect it to kick in when cannon is building (including during run steps), or when using the provider supplied by cannon after running the hardhat job (ex. when running integration tests!). In the future, this should also be usable in the frontend as well using the wrapper provider.

here is an example of the output when I just added revert("Its a failure") to the sample greeter contract:

CannonTraceError: transaction reverted: Error("Its a failure")

  CALL greeters.greeter.setGreeting("new greeting!") => Error("Its a failure")
    STATICCALL console.log("Changing greeting from '%s' to '%s'", "Hello world!", "new greeting!")

notice how the error also includes the full calldata, any intermediate
contract calls (should be amazing for multi-contract projects!), and any console.log you
may have in your code, and any errors/revert reasons seen.

here is another example where, I add a line uint testval = 1 / uint(0);:

CannonTraceError: transaction reverted: Panic("division by zero")

  CALL greeters.greeter.setGreeting("new greeting!") => Panic("division by zero")
    STATICCALL console.log("Changing greeting from '%s' to '%s'", "Hello world!", "new greeting!")

custom solidity errors are also decoded:

CannonTraceError: transaction reverted: DummyError("custom text", "42069")

  CALL greeters.greeter.setGreeting("new greeting!") =>
DummyError("custom text", "42069")
    STATICCALL console.log("Changing greeting from '%s' to '%s'", "Hello
world!", "new greeting!")

    at handleTxnError
(/home/daniel/code/cannon/packages/builder/src/error.ts:57:11)
    at processTicksAndRejections
(node:internal/process/task_queues:95:5)

if the error is not able to be decoded, the original error is returned
unmodified, so you don't need to worry about it making errors harder to
read than they already are.

Unfortunately anvil does not supply information regarding the contract
source code, which means you wont see any tracing for contract internal
calls.

using the cannon context, as it is being built live and after chain is
established, detailed error messages can be parsed and displayed to the
user!

here is an example of the output when I just added `revert("Its a failure")` to the sample greeter contract:

```
CannonTraceError: transaction reverted: Error("Its a failure")

  CALL greeters.greeter.setGreeting("new greeting!") => Error("Its a failure")
    STATICCALL console.log("Changing greeting from '%s' to '%s'", "Hello world!", "new greeting!")
```

notice how the error also includes the full calldata, any intermediate
contract calls (should be amazing for v2x!), and any `console.log` you
may have in your code, and any errors/revert reasons seen.

here is another example where, I add a line `uint testval = 1 / uint(0);`:

```
CannonTraceError: transaction reverted: Panic("division by zero")

  CALL greeters.greeter.setGreeting("new greeting!") => Panic("division by zero")
    STATICCALL console.log("Changing greeting from '%s' to '%s'", "Hello world!", "new greeting!")
```

custom solidity errors are also decoded:

```
CannonTraceError: transaction reverted: DummyError("custom text", "42069")

  CALL greeters.greeter.setGreeting("new greeting!") =>
DummyError("custom text", "42069")
    STATICCALL console.log("Changing greeting from '%s' to '%s'", "Hello
world!", "new greeting!")

    at handleTxnError
(/home/daniel/code/cannon/packages/builder/src/error.ts:57:11)
    at processTicksAndRejections
(node:internal/process/task_queues:95:5)
```

if the error is not able to be decoded, the original error is returned
unmodified, so you don't need to worry about it making errors harder to
read than they already are.

Unfortunately anvil does not supply information regarding the contract
source code, which means you wont see any tracing for contract internal
calls.
@dbeal-eth dbeal-eth self-assigned this Sep 1, 2022
@netlify
Copy link

netlify bot commented Sep 1, 2022

Deploy Preview for usecannon canceled.

Name Link
🔨 Latest commit 5127f9c
🔍 Latest deploy log https://app.netlify.com/sites/usecannon/deploys/63107f423da69200088ca410

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

Successfully merging this pull request may close these issues.

None yet

2 participants