Document RPC error codes #1908

pull laanwj wants to merge 2 commits into bitcoin:master from laanwj:2012_10_rpcerrors changing 7 files +159 −112
  1. laanwj commented at 8:54 AM on October 4, 2012: member

    I performed some code archeology to retroactively name and document the JSONRPC error codes.

    This pull has no code changes.

    Feel free to suggest other names for the errors.

    // Bitcoin RPC error codes
    enum RPCErrorCode
    {
        // Standard JSON-RPC 2.0 errors
        RPC_INVALID_REQUEST  = -32600,
        RPC_METHOD_NOT_FOUND = -32601,
        RPC_INVALID_PARAMS   = -32602,
        RPC_INTERNAL_ERROR   = -32603,
        RPC_PARSE_ERROR      = -32700,
    
        // General application defined errors
        RPC_MISC_ERROR                  = -1,  // std::exception thrown in command handling
        RPC_FORBIDDEN_BY_SAFE_MODE      = -2,  // Server is in safe mode, and command is not allowed in safe mode
        RPC_TYPE_ERROR                  = -3,  // Unexpected type was passed as parameter
        RPC_INVALID_ADDRESS_OR_KEY      = -5,  // Invalid address or key
        RPC_OUT_OF_MEMORY               = -7,  // Ran out of memory during operation
        RPC_INVALID_PARAMETER           = -8,  // Invalid, missing or duplicate parameter
        RPC_DATABASE_ERROR              = -20, // Database error
        RPC_DESERIALIZATION_ERROR       = -22, // Error parsing or validating structure in raw format
    
        // P2P client errors
        RPC_CLIENT_NOT_CONNECTED        = -9,  // Bitcoin is not connected
        RPC_CLIENT_IN_INITIAL_DOWNLOAD  = -10, // Still downloading initial blocks
    
        // Wallet errors
        RPC_WALLET_ERROR                = -4,  // Unspecified problem with wallet (key not found etc.)
        RPC_WALLET_INSUFFICIENT_FUNDS   = -6,  // Not enough funds in wallet or account
        RPC_WALLET_INVALID_ACCOUNT_NAME = -11, // Invalid account name
        RPC_WALLET_KEYPOOL_RAN_OUT      = -12, // Keypool ran out, call keypoolrefill first
        RPC_WALLET_UNLOCK_NEEDED        = -13, // Enter the wallet passphrase with walletpassphrase first
        RPC_WALLET_PASSPHRASE_INCORRECT = -14, // The wallet passphrase entered was incorrect
        RPC_WALLET_WRONG_ENC_STATE      = -15, // Command given in wrong wallet encryption state (encrypting an encrypted wallet etc.)
        RPC_WALLET_ENCRYPTION_FAILED    = -16, // Failed to encrypt the wallet
        RPC_WALLET_ALREADY_UNLOCKED     = -17, // Wallet is already unlocked
    };
    

    This pull reveals some inconsistencies in the error codes thrown, for example, -3 is sometimes used for "Invalid bitcoin address" sometimes i.s.o -5, but as to not change the interface I decided against addressing this. This can be left for a later pull (or never, and just documented as part of the API).

    I've also added constants for the HTTP status codes.

  2. Diapolo commented at 9:52 AM on October 4, 2012: none

    I love it as it makes the code so much more readable, great pull IMO.

  3. Document RPC error codes
    Replace all "magic values" in RPCError(...) by constants.
    738835d7b8
  4. Add constants for HTTP status codes 285746d3db
  5. sipa commented at 9:10 PM on October 4, 2012: member

    ACK.

  6. jgarzik commented at 9:14 PM on October 4, 2012: contributor

    ACK

  7. gavinandresen commented at 9:36 PM on October 4, 2012: contributor

    ACK

  8. sipa referenced this in commit 39930ca6ae on Oct 5, 2012
  9. sipa merged this on Oct 5, 2012
  10. sipa closed this on Oct 5, 2012

  11. brotchie referenced this in commit 63af4fd7ab on Jan 30, 2014
  12. laanwj deleted the branch on Apr 9, 2014
  13. KolbyML referenced this in commit 48e3c91e8c on Dec 5, 2020
  14. DrahtBot 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:16 UTC

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