foundry icon indicating copy to clipboard operation
foundry copied to clipboard

Better error reporting when interacting with undeployed contracts

Open PaulRBerg opened this issue 3 years ago • 3 comments

Component

Forge

Describe the feature you would like

I have bumped into many EvmError errors that were caused by an attempt to interact with a contract which was either undeployed already or was deployed to a local network and by the time I was making the call, the contract did no longer exist because I had used a fork cheatcode.

I think that this is such a common scenario that it would be extremely helpful (and prevent many angry reports in the Foundry Support group) for Foundry to handle this sort of error more gracefully and display a clearer error, e.g.:

You have attempted to make a call to address 0xCAFE..., but not contract is present there

PaulRBerg avatar Jan 20 '23 14:01 PaulRBerg

Another related use case - calling undeployed library functions.

When library functions are declared as public or external, the library must be deployed separately and then linked before it can be used.

PaulRBerg avatar Feb 08 '23 09:02 PaulRBerg

I keep bumping into this issue every time I make a new deployment which I need to cross-reference in another repository - I forget to bump the block number.

The error message is generic and difficult to reverse engineer:

Screenshot 2023-06-18 at 4 32 26 PM

PaulRBerg avatar Jun 18 '23 13:06 PaulRBerg

sg @PaulRBerg — agreed we could probably improve this error. Will take a stab at this during the next week to see if we can improve this

Evalir avatar Jun 18 '23 19:06 Evalir

I've bumped into the same situation again and spent ~15 minutes that would have been spared had Foundry detected that the contract doesn't exist on the network.

cc @grandizzy

I suspect this is a common debugging situation, especially when running tests against mainnet forks.

PaulRBerg avatar Apr 23 '25 11:04 PaulRBerg

@PaulRBerg there is a fix in nightly to provide more details if test run with verbosity / traces, would you mind give it a try and provide feedback? Thank you!

grandizzy avatar May 22 '25 03:05 grandizzy

ooh this is exactly what I needed! I ran the tests with -vvv (three verbosity flags), and I got this error:

[FAIL: call to non-contract address 0xcaFe00000000000000000000000000000000BeeF] setUp() (gas: 0)

However, the error doesn't show up when I run it with -vv or -v. Why?

In those cases, I only see:

[FAIL: EvmError: Revert] setUp() (gas: 0)

I think this is such a confusing scenario to be in as a developer that I recommend displaying the error by default, in all cases, even if no verbosity flag is provided.

cc @smol-ninja and @andreivladbrg, FYI

PaulRBerg avatar May 23 '25 12:05 PaulRBerg

ooh this is exactly what I needed! I ran the tests with -vvv (three verbosity flags), and I got this error:

[FAIL: call to non-contract address 0xcaFe00000000000000000000000000000000BeeF] setUp() (gas: 0)

However, the error doesn't show up when I run it with -vv or -v. Why?

In those cases, I only see:

[FAIL: EvmError: Revert] setUp() (gas: 0)

I think this is such a confusing scenario to be in as a developer that I recommend displaying the error by default, in all cases, even if no verbosity flag is provided.

cc @smol-ninja and @andreivladbrg, FYI

the fix comes with some extra performance overhead, as we need to inspect every opcode.

because of that, in our opinion, it makes sense to limit the feature to those scenarios when devs are debugging and want to figure out why they got the generic revert.

0xrusowsky avatar May 23 '25 12:05 0xrusowsky

Fair enough!

PaulRBerg avatar May 23 '25 12:05 PaulRBerg