bitcoin-cli: Provide a better error message when bitcoind is not running #12652

pull practicalswift wants to merge 3 commits into bitcoin:master from practicalswift:bitcoin-cli-error-message-when-bitcoind-is-not-running changing 2 files +25 −11
  1. practicalswift commented at 5:41 AM on March 9, 2018: contributor

    Provide a better bitcoin-cli error message when bitcoind is not running.

    Before this patch:

    $ killall -9 bitcoind
    $ bitcoin-cli -testnet echo 'hello world'
    error: Could not locate RPC credentials. No authentication cookie could be found, and RPC password is not set.  See -rpcpassword and -stdinrpcpass.  Configuration file: (/root/.bitcoin/bitcoin.conf)
    

    After this patch:

    $ killall -9 bitcoind
    $ bitcoin-cli -testnet echo 'hello world'
    error: Could not connect to the server 127.0.0.1:18332
    
    Make sure the bitcoind server is running and that you are connecting to the correct RPC port.
    
  2. practicalswift force-pushed on Mar 9, 2018
  3. practicalswift force-pushed on Mar 9, 2018
  4. practicalswift force-pushed on Mar 9, 2018
  5. practicalswift force-pushed on Mar 9, 2018
  6. randolf approved
  7. jonasschnelli commented at 6:33 AM on March 9, 2018: contributor

    I guess you need to fix the interface_bitcoin_cli.py test.

  8. meshcollider added the label Utils/log/libs on Mar 9, 2018
  9. bitcoin-cli: Provide a better error message when bitcoind is not running
    Before this patch:
    
    ```
    $ bitcoin-cli -testnet echo 'hello world'
    error: Could not locate RPC credentials. No authentication cookie could be found, and RPC password is not set.  See -rpcpassword and -stdinrpcpass.  Configuration file: (/root/.bitcoin/bitcoin.conf)
    ```
    
    After this patch:
    
    ```
    $ bitcoin-cli -testnet echo 'hello world'
    error: Could not connect to the server 127.0.0.1:18332
    
    Make sure the bitcoind server is running and that you are connecting to the correct RPC port.
    ```
    de04fde534
  10. practicalswift force-pushed on Mar 9, 2018
  11. practicalswift commented at 2:54 PM on March 9, 2018: contributor

    @jonasschnelli Oh, thanks! Fixed. Please re-review :-)

  12. cdecker commented at 5:54 PM on March 9, 2018: contributor

    utACK de04fde

  13. practicalswift cross-referenced this on Mar 9, 2018 from issue Improve onboarding experience by handling common failure scenarios for new users more gracefully by practicalswift
  14. practicalswift cross-referenced this on Mar 9, 2018 from issue bitcoin-cli exec failed: No such file or directory by kryo2k
  15. laanwj commented at 12:31 PM on March 10, 2018: member

    Concept ACK.

    However I remember making the code like this to avoid certain edge cases around the authentication credentials and connectability.

    Can we please add tests for this? This logic was already complicated, and this makes it even more complicated.

  16. in src/bitcoin-cli.cpp:368 in de04fde534 outdated
     368 | +        }
     369 | +        throw CConnectionFailed(strprintf("Could not connect to the server %s:%d%s\n\nMake sure the bitcoind server is running and that you are connecting to the correct RPC port.", host, port, responseErrorMessage));
     370 | +    } else if (response.status == HTTP_UNAUTHORIZED) {
     371 | +        if (failedToGetAuthCookie) {
     372 | +            throw std::runtime_error(strprintf(
     373 | +                _("Could not locate RPC credentials. No authentication cookie could be found, and RPC password is not set.  See -rpcpassword and -stdinrpcpass.  Configuration file: (%s)"),
    


    MarcoFalke commented at 9:52 PM on March 11, 2018:

    Mind to add a test for this?


    practicalswift commented at 9:46 PM on March 19, 2018:

    Added :-)

  17. in src/bitcoin-cli.cpp:364 in de04fde534 outdated
     364 | +    if (response.status == 0) {
     365 | +        std::string responseErrorMessage;
     366 | +        if (response.error != -1) {
     367 | +            responseErrorMessage = strprintf(" (error code %d - \"%s\")", response.error, http_errorstring(response.error));
     368 | +        }
     369 | +        throw CConnectionFailed(strprintf("Could not connect to the server %s:%d%s\n\nMake sure the bitcoind server is running and that you are connecting to the correct RPC port.", host, port, responseErrorMessage));
    


    MarcoFalke commented at 9:53 PM on March 11, 2018:

    Same here. Should come with a test.


    practicalswift commented at 9:46 PM on March 19, 2018:

    Added :-)

  18. practicalswift commented at 9:43 PM on March 19, 2018: contributor

    Tests added. Please re-review :-)

  19. tests: Test connecting to a non-existing server a2b2476e96
  20. tests: Test connecting with non-existing RPC cookie file 8b2ef27ff9
  21. practicalswift force-pushed on Mar 19, 2018
  22. laanwj commented at 9:42 AM on March 20, 2018: member

    utACK 8b2ef27ff9be20fc1a53d8804b403859251f1fca / tests look good to me, thanks for adding them.

  23. laanwj merged this on Mar 20, 2018
  24. laanwj closed this on Mar 20, 2018

  25. laanwj referenced this in commit 55f490a79f on Mar 20, 2018
  26. MarcoFalke cross-referenced this on Mar 29, 2018 from issue importaddress error (p2sh) by brett-doffing
  27. markblundeberg referenced this in commit 360670aa78 on Jun 21, 2019
  28. jtoomim referenced this in commit 74bdb54fe7 on Jun 29, 2019
  29. PastaPastaPasta referenced this in commit 04704bea07 on Jun 10, 2020
  30. PastaPastaPasta referenced this in commit e2612ee16d on Jun 13, 2020
  31. PastaPastaPasta referenced this in commit 24a2ebb689 on Jun 13, 2020
  32. PastaPastaPasta referenced this in commit 4f3a0974fc on Jun 13, 2020
  33. PastaPastaPasta referenced this in commit 7007aabb86 on Jun 17, 2020
  34. practicalswift deleted the branch on Apr 10, 2021
  35. furszy cross-referenced this on Jan 10, 2022 from issue Add options -stdin and -stdinrpcpass to pivx-cli by furszy
  36. gades referenced this in commit 8553bfd920 on Mar 15, 2022
  37. bitcoin locked this on Aug 18, 2022

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-05-20 06:55 UTC