Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Display revert reasoning string in exception. #976

Closed
1 task
kyriediculous opened this issue May 31, 2018 · 20 comments
Closed
1 task

Display revert reasoning string in exception. #976

kyriediculous opened this issue May 31, 2018 · 20 comments
Labels

Comments

@kyriediculous
Copy link


Issue

It seems that, in contrast to Remix, truffle does not yet display the reasoning strings that can be added to Revert/Require since solidity 0.4.22

Steps to Reproduce

Make a function that reverts with a message and call it from a unit test, console.error() the exception.

contract Test {
function test() {
  revert("I reverted")
}
}

Expected Behavior


VM error: revert. The transaction has been reverted to the initial state.
**Reason provided by the contract: "I reverted".**
Debug the transaction to get more information. 

Actual Results

Error: VM Exception while processing transaction: revert

Environment

  • Operating System: Win10 Pro
  • Ethereum client: Ganache
  • Truffle version (truffle version): Truffle v4.1.8 (core: 4.1.9)
  • Solidity version: v0.4.24 (solc-js)
  • node version (node --version): 8.11.2
  • npm version (npm --version): 5.6.0
@cgewecke
Copy link
Contributor

cgewecke commented May 31, 2018

@kyriediculous Yes!! Super excited about this. Current status is:

  • Remix gets the reason string because it runs ethereumjs-vm in the browser and can just grab the return data directly out of the vm. The clients' default behavior is to throw that data away rather than include it in the response, so we need changes at that layer to be able to do the same thing.

  • Ganache just merged a PR last week that attaches return data to the error message on eth_call. That change is queued for the next release. As soon as it becomes available we'll begin work on integrating this into the next version of truffle-contract.

  • Finally, the other clients are still working on their implementations so it will probably be a bit before getting the reason string is a fully integrated feature. We're tracking those developments at ganache here and that issue links out to work being done at Geth.

Thanks for opening.

@kyriediculous
Copy link
Author

Awesome, thanks for being on top of it !

@kronosapiens
Copy link

Hi! Also interested in this issue. Will the new version of Ganache also pass along require failure messages?

@cgewecke
Copy link
Contributor

cgewecke commented Jun 18, 2018

@kronosapiens

On eth_call, [email protected] now returns a specially formatted error result that encodes the reason string. In the version of truffle-contract being written for V5, every transaction gets gas estimated first (and routed through eth_call) so we capture the return data there. You can see one strategy for extracting it as intelligible string in on the async-deployer branch here.

There is also a nice PR open at ganache to do the decoding there.

@kronosapiens
Copy link

Thanks for the update! Is there anything I could help with or is it just waiting for things to be merged and released?

@cgewecke
Copy link
Contributor

@kronosapiens Yes it's kind of the latter. The reason string logic looks like it's working. It's bound up with a pull-request that targets the next major release and is a rewrite truffle's migrations command. That should go into review next week and be available as an alpha (or something) relatively soon.

Thanks so much for your offer of help - really nice of you. Because we're coming up on a release the main thing that needs to be done is stress-testing the new code. Migrations are an especially complicated case - there are multiple clients which people connect to in several different ways with variant responses happening at different time scales.

Will definitely ping this issue when there's a build of this available (so you can see where it's broken :).)

@roschler
Copy link

@cgewecke This is fantastic news! I assume the debugger will display it during a session?

@cgewecke
Copy link
Contributor

cgewecke commented Jun 18, 2018

@roschler I'm not sure about that actually - it should be visible in the source mapping display though. What's your take on how this should work?

@cgewecke
Copy link
Contributor

cgewecke commented Jul 26, 2018

Small update: - truffle@next contains reason string handling and it seems to be working ok based on some early experimental use over at EthPM and Colony. There is a draft release notes open as a PR here with instructions and info about breaking changes to truffle-contract.

We're getting ready to release a beta soon - the next tag is an unstable preview / nightly for that . . .

$ npm install truffle@next

@kyriediculous
Copy link
Author

Cool ! I will check it out over the weekend and report my findings! Many thanks.

@benjamincburns
Copy link
Contributor

Turns out we didn't have the reason string in the ganache-core log (which in turn feeds the Ganache log view), so I added it just now. trufflesuite/ganache@8d311f3

Not sure when this will make it out for release - I'd guess sometime in the next couple of weeks. That said I'm in the process of automating our releases so that we'll be able to push out smaller improvements like this more frequently.

@eloudsa
Copy link

eloudsa commented Sep 23, 2018

Hi
I have installed the beta version of Truffle (v5.0.0-beta.0) and tried to display the error reason thrown in my contract. I have followed this: https://github.com/trufflesuite/truffle/releases#reason-strings

I tried displaying the error reason string in my JS test without success. The error string is always "Transaction has been reverted by the EVM" even if my test is running on ganache-cli version 2.2.1.

Is there a specific path or constraint to follow in order to display the error reason strings or is it too early to implement such features?
Thanks

@danaki
Copy link

danaki commented Sep 23, 2018

I used these reasoning strings in my contracts until I got my contract so huge that it couldn't fit into ethereum transaction limit. I would like to see these reasoning strings in tests to distinguish one case from another but can skip for production use. Is it possible somehow?

@cgewecke
Copy link
Contributor

@eloudsa We have some unit tests that verify that the reason string works as expected with ganache here (for ganache when its --noVMErrorsOnRPCResponse flag is set to true) and here for the default case. If you have a chance could you look at those and see if there are any obvious differences between your implementation and ours? Could you also verify that you're not accidentally connecting to a non-ganache client running in the background?

@danaki There is a ganache-cli option which lets you turn off the contract size limit: allowUnlimitedContractSize

@eloudsa
Copy link

eloudsa commented Sep 23, 2018

@cgewecke Thanks for your reply. I'm using ganache as I can check transactions in the console window. Without the --noVMErrorsOnRPCResponse flag, the reason string message is displayed in the error message. But, the reason remains undefined. Do you have a any small truffle project (contract and test) I can use to check my environment?

@cgewecke Another issue: If I run ganache-cli with a block time, the reason is not more displayed.

@roschler
Copy link

roschler commented Sep 23, 2018 via email

@gnidan
Copy link
Contributor

gnidan commented Jan 16, 2019

This should be released and available in v5. Let us know if we missed a use case and we'll re-open. Thank you!

@gnidan gnidan closed this as completed Jan 16, 2019
@kyriediculous
Copy link
Author

Been using truffle ^5.0.0 for some weeks now and the reasoning strings work very well while testing.
Much clearer than before when running into reverts, saves a ton of time.

10/10

@qiluge
Copy link

qiluge commented Feb 24, 2021

My ganache GUI version is v2.5.4, truffle version is v5.1.57. But I cannot got error reason string when the transaction revert!
When I change to use ganache-cli v6.12.2 (ganache-core: 2.13.2), still unable to get the return of the error message.

@benjamincburns
Copy link
Contributor

@qiluge best to open a new issue for this

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

No branches or pull requests

9 participants