-
Notifications
You must be signed in to change notification settings - Fork 20.7k
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
accounts/abi/bind, eth: add contract non-existent error #2496
accounts/abi/bind, eth: add contract non-existent error #2496
Conversation
Updated: Wed Apr 27 14:24:06 UTC 2016 |
@fjl Please review |
// If there's no code to interact with, respond with an appropriate error | ||
if args.To != nil { | ||
if code := stateDb.GetCode(*args.To); len(code) == 0 { | ||
return "0x", nil, bind.ErrNonExistentContract |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like the cross-dependency on accounts/abi/bind
. Maybe the error can live in package eth instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had that originally, but I need to return this same error from bind/backends
, which would create a dependency on eth
and then I couldn't any more use native daps within eth
due to circular dependencies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, perhaps it's still possible since eth wouldn't depend on the backends package, only on bind. But the tests would still need to go then into eth_test to be able to pull in the simulator (or we don't test the contract integration :P)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All in all it seemed a bit large of a dependency to pull in the entire eth protocol just to handle a 3 word error string.
Maybe the error should be "no code" instead, given that it checks for that. Contracts with empty code can exist and would trigger the error otherwise. |
// ErrNoContractCode is returned by call and transact operations for which the
// requested recipient contract to operate on does not exist in the state db or
// does not have any code associated with it (i.e. suicided).
var ErrNoContractCode = errors.New("no contract code") like this? |
would prefer |
b810006
to
d30ba7b
Compare
d30ba7b
to
cdcbb2f
Compare
@fjl PTAL |
👍 for now, but we should really add the error code |
I agree. Looked at it but it would overlap with som changes Bas is making currently (like renaming RPCError to Error) and other parts of the code. Also it would require us defining some proper application level error codes and messages, which is not a quick fix. I'm all in for doing that, but that can wait for 1.5. |
Current coverage is 50.84%@@ develop #2496 diff @@
==========================================
Files 209 209
Lines 29521 29525 +4
Methods 0 0
Messages 0 0
Branches 0 0
==========================================
- Hits 15019 15010 -9
- Misses 13396 13408 +12
- Partials 1106 1107 +1
|
This PR adds a
non-existent contract
error message to theeth
API'scall
andestimateGas
methods to properly distinguish this specific error message. It further adds this error to the Go ABI bindingsimulated
backend as well as implements detecting this in theremote
backend too.This PR is specifically important to make it both obvious if a native dapp call fails due to a bad contract address and/or not being in sync, but also so that we can programatically gracefully handle these scenarios (i.e. don't crash, just postpone the call (e.g. versions check) until the contract becomes available).
Edit: Long term we probably would want to assign a JSON RPC error code specifically to this failure so we don't have to rely on the error string contents to convert the textual failure into our specific internal Go failure type.