[bitcoin-cli] improve error output #6387

pull jonasschnelli wants to merge 1 commits into bitcoin:master from jonasschnelli:2015/07/bitcoin-cli-error-output changing 1 files +9 −0
  1. jonasschnelli commented at 10:19 AM on July 7, 2015: contributor

    [only affects bitcoin-cli]

    At the moment, errors in bitcoin-cli are sent to stderr as compact json string. Example:

    jonasschnelli$ ./src/bitcoin-cli -regtest sendtoaddress 276536543
    error: {"code":-1,"message":"sendtoaddress \"bitcoinaddress\" amount ( \"comment\" \"comment-to\" 
    subtractfeefromamount )\n\nSend an amount to a given address. The amount is a real and is rounded to the nearest 0.00000001\n\nArguments:\n1. \"bitcoinaddress\"  (string, required) The bitcoin address to 
    send to.\n2. \"amount\"      (numeric, required) The amount in btc to send. eg 0.1\n3. \"comment\"     (string, optional) A comment used to store what the transaction is for. \n                             This is not part 
    of the transaction, just kept in your wallet.\n4. \"comment-to\"  (string, optional) A comment to store the name of the person or organization \n                             to which you're sending the transaction. This is 
    not part of the \n                             transaction, just kept in your wallet.\n5. subtractfeefromamount  (boolean, optional, default=false) The fee will be deducted from the amount being sent.\n                             
    The recipient will receive less bitcoins than you enter in the amount field.\n\nResult:\n\"transactionid\"  (string) The transaction id.\n\nExamples:\n> bitcoin-cli sendtoaddress 
    \"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" 0.1\n> bitcoin-cli sendtoaddress \"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" 0.1 \"donation\" \"seans outpost\"\n> bitcoin-cli 
    sendtoaddress \"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" 0.1 \"\" \"\" true\n> curl --user myusername --data-binary '{\"jsonrpc\": \"1.0\", \"id\":\"curltest\", \"method\": \"sendtoaddress\", \"params\": 
    [\"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\", 0.1, \"donation\", \"seans outpost\"] }' -H 'content-type: text/plain;' http://127.0.0.1:8332/\n"}
    
    

    This PR would format the error message and error code so that it's better readable. Example after this PR:

    jonasschnelli$ ./src/bitcoin-cli --regtest sendtoaddress mvDv4Z
    error code: -1
    error message:
    sendtoaddress "bitcoinaddress" amount ( "comment" "comment-to" subtractfeefromamount )
    
    Send an amount to a given address. The amount is a real and is rounded to the nearest 0.00000001
    
    Arguments:
    1. "bitcoinaddress"  (string, required) The bitcoin address to send to.
    2. "amount"      (numeric, required) The amount in btc to send. eg 0.1
    3. "comment"     (string, optional) A comment used to store what the transaction is for. 
                                 This is not part of the transaction, just kept in your wallet.
    4. "comment-to"  (string, optional) A comment to store the name of the person or organization 
                                 to which you're sending the transaction. This is not part of the 
                                 transaction, just kept in your wallet.
    5. subtractfeefromamount  (boolean, optional, default=false) The fee will be deducted from the amount being sent.
                                 The recipient will receive less bitcoins than you enter in the amount field.
    
    Result:
    "transactionid"  (string) The transaction id.
    
    Examples:
    > bitcoin-cli sendtoaddress "1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd" 0.1
    > bitcoin-cli sendtoaddress "1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd" 0.1 "donation" "seans outpost"
    > bitcoin-cli sendtoaddress "1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd" 0.1 "" "" true
    > curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "sendtoaddress", "params": ["1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd", 0.1, "donation", "seans outpost"] }' -H 'content-type: text/plain;' http://127.0.0.1:8332/
    
    
  2. jonasschnelli force-pushed on Jul 7, 2015
  3. laanwj added the label RPC on Jul 7, 2015
  4. jgarzik commented at 2:42 PM on July 7, 2015: contributor

    ACK

  5. in src/bitcoin-cli.cpp:None in 9c7d0dd09c outdated
     189 | @@ -190,6 +190,15 @@ int CommandLineRPC(int argc, char *argv[])
     190 |                          throw CConnectionFailed("server in warmup");
     191 |                      strPrint = "error: " + error.write();
    


    laanwj commented at 2:43 PM on July 7, 2015:

    Maybe not print the whole object, when we print the nicely formatted error?

    What has always held me back from doing this (sensible) thing is that scripts may be relying on bitcoin-cli's output for errors to be as it is.


    jonasschnelli commented at 3:23 PM on July 7, 2015:

    This line strPrint = "error: " + error.write(); get's overwritten at L198 when error.isObject() (currently always). Hmm... if someone relies on a/the output of a RPC client application like bitcoin-cli he should definitively rethink his API design and probably directly use the JSON RPC API.


    laanwj commented at 3:32 PM on July 7, 2015:

    Ok, fair enough. utACK.


    jgarzik commented at 3:39 PM on July 7, 2015:

    Agree / @jonasschnelli

  6. jonasschnelli force-pushed on Jul 7, 2015
  7. [bitcoin-cli] improve error output 65ce0215a4
  8. jonasschnelli force-pushed on Jul 7, 2015
  9. laanwj commented at 4:38 PM on July 7, 2015: member

    Travis error was unrelated (see #6391)

  10. laanwj merged this on Jul 8, 2015
  11. laanwj closed this on Jul 8, 2015

  12. laanwj referenced this in commit 11576a57d2 on Jul 8, 2015
  13. zkbot referenced this in commit df07f9ad23 on Feb 15, 2017
  14. zkbot referenced this in commit ec069ce96c on Mar 3, 2017
  15. zkbot referenced this in commit 702eefc71a on Mar 3, 2017
  16. zkbot referenced this in commit 99c4c6de0c on Mar 3, 2017
  17. MarcoFalke locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-13 15:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me