bitcoin-cli returns 1 on success and 0 on error. By convention it should be the other way round.
It is not possible to distinguish between different error codes, all errors return 0. But for an AppInitRPC error, we would return 1...
bitcoin-cli returns 1 on success and 0 on error. By convention it should be the other way round.
It is not possible to distinguish between different error codes, all errors return 0. But for an AppInitRPC error, we would return 1...
69 | - if(!CommandLineRPC(argc, argv)) 70 | - return 1; 71 | + ret = CommandLineRPC(argc, argv); 72 | } 73 | catch (std::exception& e) { 74 | PrintExceptionContinue(&e, "CommandLineRPC()");
Maybe we should also return 1 in the case of an exception (so don't default ret to 0)
Yes, I was also thinking about that, but I was not sure. So I will update the pull then.
update:
ACK on code changes (didn't test yet)
$ src/bitcoin-cli help; echo $?
...
0
$ src/bitcoin-cli; echo $?
... [help message] ...
1
$ src/bitcoin-cli sendtoaddress "1234" 1.0; echo $?
error: {"code":-5,"message":"Invalid Bitcoin address"}
5
src/bitcoin-cli -rpcport=6667 help; echo $?
error: couldn't connect to server
87
ACK
Nothing new in this pull, but I wonder why this returns 87. IMO it should simply be 1 (=-RPC_MISC_ERROR): https://github.com/bitcoin/bitcoin/blob/master/src/rpcclient.cpp#L236
cozz: Can you refactor the 1 and 0 into RET_SUCCESS and RET_FAIL variables?
RET_SUCCESS / RET_FAIL is not any POSIX or C standard is it? We're also not using them in any other place at the moment.
If you want to use constants, using abs(constant_from_RPCErrorCode) from src/rpcprotocol.h would make more sense as that's where the error code that are returned by CommandLineRPC (and thus by the -cli now) come from.
update:
We might break a script by changing this error code, but should be very unlikely.
Automatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/875acdf78693332a1500557ee728a4341dbe2d4c for binaries and test log. This test script verifies pulls every time they are updated. It, however, dies sometimes and fails to test properly. If you are waiting on a test, please check timestamps to verify that the test.log is moving at http://jenkins.bluematt.me/pull-tester/current/ Contact BlueMatt on freenode if something looks broken.
232 | @@ -233,10 +233,11 @@ int CommandLineRPC(int argc, char *argv[]) 233 | } 234 | catch (std::exception& e) { 235 | strPrint = string("error: ") + e.what(); 236 | - nRet = 87; 237 | + nRet = abs(RPC_MISC_ERROR); 238 | } 239 | catch (...) { 240 | PrintException(NULL, "CommandLineRPC()"); 241 | + nRet = abs(RPC_MISC_ERROR);
Execution will never get here. PrintException does a re-throw unlike PrintExceptionContinue. I'd never code it that way and would put the throw in the catch() statement itself for clarity, but this is part of our legacy.
I see. Removing this then.
ACK on the abs(RPC_MISC_ERROR) change.