bitcoin-cli: Make error message less confusing #9265

pull laanwj wants to merge 1 commits into bitcoin:master from laanwj:2016_12_rpccli_message changing 1 files +1 −1
  1. laanwj commented at 7:56 AM on December 2, 2016: member

    Sorry for the churn on this, but the current message (introduced in #9073) isn't acceptable:

    $ src/bitcoin-cli getinfo
    rpc: couldn't connect to server
    (make sure server is running and you are connecting to the correct RPC port: -1 unknown)

    Putting the error code after the words "RPC port" made me wonder whether there was a port configuration issue.

    This changes it to:

    $ src/bitcoin-cli getinfo
    error: couldn't connect to server: unknown (code -1)
    (make sure server is running and you are connecting to the correct RPC port)
  2. bitcoin-cli: Make error message less confusing
    Sorry for the churn on this, but the current message (introduced in #9073)
    isn't acceptable:
    
        $ src/bitcoin-cli getinfo
        rpc: couldn't connect to server
        (make sure server is running and you are connecting to the correct RPC port: -1 unknown)
    
    Putting the error code after the words "RPC port" made me wonder whether
    there was a port configuration issue.
    
    This changes it to:
    
        $ src/bitcoin-cli getinfo
        error: couldn't connect to server: unknown (code -1)
        (make sure server is running and you are connecting to the correct RPC port)
    fe37fbe606
  3. laanwj added the label Utils and libraries on Dec 2, 2016
  4. paveljanik commented at 9:57 AM on December 2, 2016: contributor

    Somehow, I'd expect to see the string "Connection refused" somewhere in the output, but this makes it a bit clearer, yes:

    $ ./bitcoin-master/src/bitcoin-cli
    error: couldn't connect to server
    (make sure server is running and you are connecting to the correct RPC port: -1 unknown)
    $ ./bitcoin-9265/src/bitcoin-cli
    error: couldn't connect to server: unknown (code -1)
    (make sure server is running and you are connecting to the correct RPC port)
    $
    

    ACK fe37fbe

  5. laanwj commented at 11:35 AM on December 2, 2016: member

    I'm not aware of any way of getting the underlying error OS error code from libevent. The one shown is libevent http error and every network layer error will basically get -1. But feel free to suggest a way.

    The other alternative would be to revert #9073 and leave it at that.

  6. paveljanik commented at 12:41 PM on December 2, 2016: contributor

    This prints the message I want to see:

    diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp
    index b272640..04157c0 100644
    --- a/src/bitcoin-cli.cpp
    +++ b/src/bitcoin-cli.cpp
    @@ -19,6 +19,7 @@
     
     #include <event2/event.h>
     #include <event2/http.h>
    +#include <event2/http_struct.h>
     #include <event2/buffer.h>
     #include <event2/keyvalq_struct.h>
     
    @@ -164,6 +165,9 @@ static void http_request_done(struct evhttp_request *req, void *ctx)
             return;
         }
     
    +    if (req->response_code == 0)
    +        fprintf(stderr, "PJ: Connection refused!\n");
    +    
         reply->status = evhttp_request_get_response_code(req);
     
         struct evbuffer *buf = evhttp_request_get_input_buffer(req);
    
  7. laanwj commented at 12:46 PM on December 2, 2016: member

    But that's cheating - you have no idea at that point whether the underlying error was really "connection refused". It could just as well be some other network-layer error. Printing a potentially false error would be worse for troubleshooting than not doing anything.

  8. MarcoFalke commented at 1:25 PM on December 2, 2016: member

    utACK fe37fbe

  9. paveljanik commented at 2:02 PM on December 2, 2016: contributor

    @laanwj Right. libevent hides the exact issue from us.

  10. jonasschnelli commented at 2:03 PM on December 2, 2016: contributor

    utACK fe37fbe606f099e81c693fae248c23c8f8fd5735

  11. MarcoFalke added the label Docs and Output on Dec 2, 2016
  12. MarcoFalke merged this on Dec 2, 2016
  13. MarcoFalke closed this on Dec 2, 2016

  14. MarcoFalke referenced this in commit 31bcc66786 on Dec 2, 2016
  15. kameroni commented at 1:58 PM on December 21, 2016: none

    Bonjour

  16. zkbot referenced this in commit b0afc4ba1d on Mar 22, 2017
  17. zkbot referenced this in commit f9f48667be on Mar 25, 2017
  18. codablock referenced this in commit 42fdb1d060 on Jan 16, 2018
  19. codablock referenced this in commit b7f6960c2d on Jan 16, 2018
  20. codablock referenced this in commit 5a6131a86b on Jan 17, 2018
  21. andvgal referenced this in commit 5823f57f68 on Jan 6, 2019
  22. CryptoCentric referenced this in commit 9124cf7a6d on Feb 25, 2019
  23. 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