Skip to content

Conversation

laanwj
Copy link
Member

@laanwj laanwj commented Oct 4, 2012

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.

@Diapolo
Copy link

Diapolo commented Oct 4, 2012

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

laanwj added 2 commits October 4, 2012 15:49
Replace all "magic values" in RPCError(...) by constants.
@sipa
Copy link
Member

sipa commented Oct 4, 2012

ACK.

@jgarzik
Copy link
Contributor

jgarzik commented Oct 4, 2012

ACK

1 similar comment
@gavinandresen
Copy link
Contributor

ACK

sipa added a commit that referenced this pull request Oct 5, 2012
@sipa sipa merged commit 39930ca into bitcoin:master Oct 5, 2012
brotchie added a commit to brotchie/node-dogecoin that referenced this pull request Jan 30, 2014
@laanwj laanwj deleted the 2012_10_rpcerrors branch April 9, 2014 14:19
KolbyML pushed a commit to KolbyML/bitcoin that referenced this pull request Dec 5, 2020
1947519 [Cleanup] Remove unneeded "fix" for segfault with getinfo on startup (random-zebra)
84acfa1 [RPC] Throw immediately if RPC is used when the server is in warmup (random-zebra)

Pull request description:

  **Problem**:
  Most RPC commands crash the wallet during the initialization phase.

  **Solution**:
  An attempt to fix this specifically for `getinfo` was made in bitcoin#543, checking the existence of `chainActive.Tip()`.
  A better solution, instead of checking all places that try to access the block index, (or  the chainstate, or the second layer maps, etc...), is to throw a JSON-RPC exception with any call, if the server is still in warm-up phase (returning the exact init message), directly from `CRPCTable::execute`.

  Closes bitcoin#1908

ACKs for top commit:
  furszy:
    ACK 1947519
  Fuzzbawls:
    utACK 1947519

Tree-SHA512: 4f37e512cb411473135c6d1fbb5013bddbcfca62b8a1ed6777481e90f60374480e3617ed1329a10d3cb1e614a2f17a827da2dce1da793b0db3c6b13222cdec19
@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.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants