Skip to content
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

consistent JSON return value for failed vote #1001

Merged
merged 2 commits into from
Sep 12, 2016

Conversation

nmarley
Copy link

@nmarley nmarley commented Sep 9, 2016

No description provided.

* result should be either 'success' or 'failed'
* error message belongs in 'errorMessage' field
@tgflynn
Copy link

tgflynn commented Sep 9, 2016

Looking through the rpc interface code it looks like the code is designed to throw a JSONRPCError exception when an error occurs. Unfortunately there are a number of places in rpcgovernance.cpp where this practice wasn't followed but I think this is the better fix, rather than returning a JSON object directly here.

@nmarley
Copy link
Author

nmarley commented Sep 9, 2016

I thought about that, but after looking thru the other places where it throws a JSONRPC error, it seems like that's only when a user enters the command incorrectly. In these cases it's not technically a JSONRPC error, esp. in cases where the vote is rejected because "time between votes is too soon".

But in these places the commands are entered correctly, but the vote is simply failing for some reason or other (e.g. the above example).

@UdjinM6 @schinzelh Your thoughts?

@tgflynn
Copy link

tgflynn commented Sep 9, 2016

Here's one example where JSONRPCError is thrown for an error that is not an incorrect input.

I think this is bitcoin code, so probably more likely to follow the original design intent.

https://github.com/dashpay/dash/blob/v0.12.1.x/src/wallet/rpcwallet.cpp#L249

@UdjinM6
Copy link

UdjinM6 commented Sep 10, 2016

Yep, there are lots of different rpc errors, see rpcprotocol.h

I think there is a case where throwing rpc errors is useful: there are some typical errors and you need standard, deterministic way to identify them. For example you need rpc to throw some specific predefined error code if there is some additional logic in another software using this rpc and you need to notify such software what happened exactly. Throwing such errors also indicate complete termination of command execution which is also a strong signal that smth went terribly wrong.

But I think it's ok to have error strings as a regular json output and no error thrown if execution can/should continue or no further action is needed in case of such error. For example there is no reason to throw an error for "masternode start-all" if say 1 masternode out of 10 failed to start.

I have no strong opinion about this specific case but it looks like "vote-*" commands are user-only so probably ok to have json reported errors?

I don't quite understand the reason for "vote-conf" and "vote-alias" to count failures and to have "overall" though - both of them should either fail or succeed once - multiple results could only happen for "vote-many" (but we don't have such command at all?).

@tgflynn
Copy link

tgflynn commented Sep 10, 2016

I don't really like the idea of constructing ad hoc error objects like this though. It seems error prone (ie. easy to accidentally construct a malformed object that clients won't see as an error, and I think this kind of bug may be relatively hard to spot in code review) and the client has to do more work to determine if an error occurred.

I think calling JSONRPCError ensures that the standard error information is returned but it has the disadvantage of not allowing the code to include additional details that may be useful to the caller (more likely for human debugging purposes than for automated action).

Maybe we should add an optional JSON parameter to JSONRPCError so that additional information can be easily returned.

A simpler option would be call write() on some JSON object to produce a string and pack that into the string parameter of the exception, but I don't much like that either, especially if there is any possibility the client may need to parse the additional information (as opposed to just displaying it for debugging purposes).

@UdjinM6
Copy link

UdjinM6 commented Sep 12, 2016

I'll merge this for now as it actually does fix inconsistency. We can come up with better system for rpc calls in general (if needed) in another PR.

@UdjinM6 UdjinM6 merged commit 1043252 into dashpay:v0.12.1.x Sep 12, 2016
@nmarley nmarley deleted the vote-fail-json branch September 12, 2016 01:25
@wuhuaping
Copy link

oot@iZ2zeeeup1v8x4tt6rzmr6Z:/var/www/html/mpos/cronjobs# ./findblock.php -f
PHP Fatal error: Uncaught Exception: RPC call did not return 200: HTTP error: 500 - JSON Response: [-8] Invalid blockhash in /var/www/html/mpos/include/lib/jsonRPCClient.php:120
Stack trace:
#0 /var/www/html/mpos/cronjobs/findblock.php(35): jsonRPCClient->__call('listsinceblock', Array)
#1 {main}
thrown in /var/www/html/mpos/include/lib/jsonRPCClient.php on line 120

root@iZ2zeeeup1v8x4tt6rzmr6Z:~# dash-cli getblockhash
error code: -1
error message:
getblockhash index

Returns hash of block in best-block-chain at index provided.

Arguments:

index (numeric, required) The block index
Result:
"hash" (string) The block hash

Examples:

dash-cli getblockhash 1000
curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getblockhash", "params": [1000] }' -H 'content-type: text/plain;' http://127.0.0.1:9998/
I used the old version of the wallet link, not wrong
But the new version of the wallet link is wrong

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

Successfully merging this pull request may close these issues.

None yet

4 participants