Skip to content

Fix bitcoin-cli exit status code#3736

Merged
laanwj merged 1 commit intobitcoin:masterfrom
cozz:cozz2
Feb 26, 2014
Merged

Fix bitcoin-cli exit status code#3736
laanwj merged 1 commit intobitcoin:masterfrom
cozz:cozz2

Conversation

@cozz
Copy link
Copy Markdown
Contributor

@cozz cozz commented Feb 24, 2014

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...

Comment thread src/bitcoin-cli.cpp
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should also return 1 in the case of an exception (so don't default ret to 0)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I was also thinking about that, but I was not sure.
So I will update the pull then.

@cozz
Copy link
Copy Markdown
Contributor Author

cozz commented Feb 24, 2014

update:

  • return 1 in the case of an exception

@laanwj
Copy link
Copy Markdown
Member

laanwj commented Feb 24, 2014

ACK on code changes (didn't test yet)

@laanwj laanwj added this to the 0.9.0 milestone Feb 24, 2014
@laanwj
Copy link
Copy Markdown
Member

laanwj commented Feb 25, 2014

$ 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

@laanwj
Copy link
Copy Markdown
Member

laanwj commented Feb 25, 2014

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

@mcassano
Copy link
Copy Markdown
Contributor

cozz: Can you refactor the 1 and 0 into RET_SUCCESS and RET_FAIL variables?

@laanwj
Copy link
Copy Markdown
Member

laanwj commented Feb 26, 2014

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.

@cozz
Copy link
Copy Markdown
Contributor Author

cozz commented Feb 26, 2014

update:

  • replace 1 with abs(RPC_MISC_ERROR)
  • replace 87 with abs(RPC_MISC_ERROR)

We might break a script by changing this error code, but should be very unlikely.

@BitcoinPullTester
Copy link
Copy Markdown

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.

Comment thread src/rpcclient.cpp Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Removing this then.

@laanwj
Copy link
Copy Markdown
Member

laanwj commented Feb 26, 2014

ACK on the abs(RPC_MISC_ERROR) change.

laanwj added a commit that referenced this pull request Feb 26, 2014
a719903 Fix bitcoin-cli exit status code (Cozz Lovan)
@laanwj laanwj merged commit a719903 into bitcoin:master Feb 26, 2014
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants