Skip to content

Conversation

@laanwj
Copy link
Member

@laanwj laanwj commented Dec 2, 2016

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)

Sorry for the churn on this, but the current message (introduced in bitcoin#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)
@paveljanik
Copy link
Contributor

paveljanik commented Dec 2, 2016

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

@laanwj
Copy link
Member Author

laanwj commented Dec 2, 2016 via email

@paveljanik
Copy link
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);

@laanwj
Copy link
Member Author

laanwj commented Dec 2, 2016

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.

@maflcko
Copy link
Member

maflcko commented Dec 2, 2016

utACK fe37fbe

@paveljanik
Copy link
Contributor

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

@jonasschnelli
Copy link
Contributor

utACK fe37fbe

@maflcko maflcko added the Docs label Dec 2, 2016
@maflcko maflcko merged commit fe37fbe into bitcoin:master Dec 2, 2016
maflcko pushed a commit that referenced this pull request Dec 2, 2016
fe37fbe bitcoin-cli: Make error message less confusing (Wladimir J. van der Laan)
@kameroni
Copy link

Bonjour

codablock pushed a commit to codablock/dash that referenced this pull request Jan 17, 2018
fe37fbe bitcoin-cli: Make error message less confusing (Wladimir J. van der Laan)
andvgal pushed a commit to energicryptocurrency/gen2-energi that referenced this pull request Jan 6, 2019
fe37fbe bitcoin-cli: Make error message less confusing (Wladimir J. van der Laan)
CryptoCentric pushed a commit to absolute-community/absolute that referenced this pull request Feb 25, 2019
fe37fbe bitcoin-cli: Make error message less confusing (Wladimir J. van der Laan)
@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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants