diff --git a/src/ripple/protocol/ErrorCodes.h b/src/ripple/protocol/ErrorCodes.h index 7819faf6aa..3f506ef87b 100644 --- a/src/ripple/protocol/ErrorCodes.h +++ b/src/ripple/protocol/ErrorCodes.h @@ -41,11 +41,8 @@ enum error_code_i // Programs should use error tokens. // Misc failure - rpcGENERAL, - rpcLOAD_FAILED, rpcNO_PERMISSION, rpcNO_EVENTS, - rpcNOT_STANDALONE, rpcTOO_BUSY, rpcSLOW_DOWN, rpcHIGH_FEE, @@ -59,19 +56,11 @@ enum error_code_i rpcNO_NETWORK, // Ledger state - rpcACT_EXISTS, rpcACT_NOT_FOUND, - rpcINSUF_FUNDS, rpcLGR_NOT_FOUND, rpcLGR_NOT_VALIDATED, rpcMASTER_DISABLED, - rpcNO_ACCOUNT, - rpcNO_PATH, - rpcPASSWD_CHANGED, - rpcSRC_MISSING, - rpcSRC_UNCLAIMED, rpcTXN_NOT_FOUND, - rpcWRONG_SEED, // Malformed command rpcINVALID_PARAMS, @@ -83,8 +72,6 @@ enum error_code_i rpcACT_MALFORMED, rpcALREADY_MULTISIG, rpcALREADY_SINGLE_SIG, - rpcQUALITY_MALFORMED, - rpcBAD_BLOB, rpcBAD_FEATURE, rpcBAD_ISSUER, rpcBAD_MARKET, @@ -99,21 +86,14 @@ enum error_code_i rpcDST_AMT_MALFORMED, rpcDST_AMT_MISSING, rpcDST_ISR_MALFORMED, - rpcGETS_ACT_MALFORMED, - rpcGETS_AMT_MALFORMED, - rpcHOST_IP_MALFORMED, rpcLGR_IDXS_INVALID, rpcLGR_IDX_MALFORMED, - rpcPAYS_ACT_MALFORMED, - rpcPAYS_AMT_MALFORMED, - rpcPORT_MALFORMED, rpcPUBLIC_MALFORMED, rpcSIGNING_MALFORMED, rpcSENDMAX_MALFORMED, rpcSRC_ACT_MALFORMED, rpcSRC_ACT_MISSING, rpcSRC_ACT_NOT_FOUND, - rpcSRC_AMT_MALFORMED, rpcSRC_CUR_MALFORMED, rpcSRC_ISR_MALFORMED, rpcSTREAM_MALFORMED, @@ -123,6 +103,7 @@ enum error_code_i rpcINTERNAL, // Generic internal error. rpcNOT_IMPL, rpcNOT_SUPPORTED, + rpcLAST = rpcNOT_SUPPORTED // rpcLAST should always equal the last code. }; //------------------------------------------------------------------------------ diff --git a/src/ripple/protocol/impl/ErrorCodes.cpp b/src/ripple/protocol/impl/ErrorCodes.cpp index 20078c3bd4..e46e7729bf 100644 --- a/src/ripple/protocol/impl/ErrorCodes.cpp +++ b/src/ripple/protocol/impl/ErrorCodes.cpp @@ -18,6 +18,7 @@ //============================================================================== #include +#include #include #include #include @@ -51,14 +52,12 @@ public: : m_unknown (rpcUNKNOWN, "unknown", "An unknown error code.") { add (rpcACT_BITCOIN, "actBitcoin", "Account is bitcoin address."); - add (rpcACT_EXISTS, "actExists", "Account already exists."); add (rpcACT_MALFORMED, "actMalformed", "Account malformed."); add (rpcACT_NOT_FOUND, "actNotFound", "Account not found."); add (rpcALREADY_MULTISIG, "alreadyMultisig", "Already multisigned."); add (rpcALREADY_SINGLE_SIG, "alreadySingleSig", "Already single-signed."); add (rpcAMENDMENT_BLOCKED, "amendmentBlocked", "Amendment blocked, need upgrade."); add (rpcATX_DEPRECATED, "deprecated", "Use the new API or specify a ledger range."); - add (rpcBAD_BLOB, "badBlob", "Blob must be a non-empty hex string."); add (rpcBAD_FEATURE, "badFeature", "Feature unknown or invalid."); add (rpcBAD_ISSUER, "badIssuer", "Issuer account malformed."); add (rpcBAD_MARKET, "badMarket", "No such market."); @@ -72,14 +71,10 @@ public: add (rpcDST_ACT_MISSING, "dstActMissing", "Destination account not provided."); add (rpcDST_ACT_NOT_FOUND, "dstActNotFound", "Destination account not found."); add (rpcDST_AMT_MALFORMED, "dstAmtMalformed", "Destination amount/currency/issuer is malformed."); + add (rpcDST_AMT_MISSING, "dstAmtMissing", "Destination amount/currency/issuer is missing."); add (rpcDST_ISR_MALFORMED, "dstIsrMalformed", "Destination issuer is malformed."); add (rpcFORBIDDEN, "forbidden", "Bad credentials."); - add (rpcGENERAL, "general", "Generic error reason."); - add (rpcGETS_ACT_MALFORMED, "getsActMalformed", "Gets account malformed."); - add (rpcGETS_AMT_MALFORMED, "getsAmtMalformed", "Gets amount malformed."); add (rpcHIGH_FEE, "highFee", "Current transaction fee exceeds your limit."); - add (rpcHOST_IP_MALFORMED, "hostIpMalformed", "Host IP is malformed."); - add (rpcINSUF_FUNDS, "insufFunds", "Insufficient funds."); add (rpcINTERNAL, "internal", "Internal error."); add (rpcINVALID_PARAMS, "invalidParams", "Invalid parameters."); add (rpcJSON_RPC, "json_rpc", "JSON-RPC transport error."); @@ -87,48 +82,40 @@ public: add (rpcLGR_IDX_MALFORMED, "lgrIdxMalformed", "Ledger index malformed."); add (rpcLGR_NOT_FOUND, "lgrNotFound", "Ledger not found."); add (rpcLGR_NOT_VALIDATED, "lgrNotValidated", "Ledger not validated."); - add (rpcLOAD_FAILED, "loadFailed", "Load failed"); add (rpcMASTER_DISABLED, "masterDisabled", "Master key is disabled."); add (rpcNOT_ENABLED, "notEnabled", "Not enabled in configuration."); add (rpcNOT_IMPL, "notImpl", "Not implemented."); add (rpcNOT_READY, "notReady", "Not ready to handle this request."); - add (rpcNOT_STANDALONE, "notStandAlone", "Operation valid in debug mode only."); add (rpcNOT_SUPPORTED, "notSupported", "Operation not supported."); - add (rpcNO_ACCOUNT, "noAccount", "No such account."); add (rpcNO_CLOSED, "noClosed", "Closed ledger is unavailable."); add (rpcNO_CURRENT, "noCurrent", "Current ledger is unavailable."); add (rpcNO_EVENTS, "noEvents", "Current transport does not support events."); add (rpcNO_NETWORK, "noNetwork", "Not synced to Ripple network."); - add (rpcNO_PATH, "noPath", "Unable to find a ripple path."); add (rpcNO_PERMISSION, "noPermission", "You don't have permission for this command."); add (rpcNO_PF_REQUEST, "noPathRequest", "No pathfinding request in progress."); - add (rpcPASSWD_CHANGED, "passwdChanged", "Wrong key, password changed."); - add (rpcPAYS_ACT_MALFORMED, "paysActMalformed", "Pays account malformed."); - add (rpcPAYS_AMT_MALFORMED, "paysAmtMalformed", "Pays amount malformed."); - add (rpcPORT_MALFORMED, "portMalformed", "Port is malformed."); add (rpcPUBLIC_MALFORMED, "publicMalformed", "Public key is malformed."); - add (rpcQUALITY_MALFORMED, "qualityMalformed", "Quality malformed."); add (rpcSIGNING_MALFORMED, "signingMalformed", "Signing of transaction is malformed."); add (rpcSLOW_DOWN, "slowDown", "You are placing too much load on the server."); add (rpcSRC_ACT_MALFORMED, "srcActMalformed", "Source account is malformed."); add (rpcSRC_ACT_MISSING, "srcActMissing", "Source account not provided."); add (rpcSRC_ACT_NOT_FOUND, "srcActNotFound", "Source account not found."); - add (rpcSRC_AMT_MALFORMED, "srcAmtMalformed", "Source amount/currency/issuer is malformed."); add (rpcSRC_CUR_MALFORMED, "srcCurMalformed", "Source currency is malformed."); add (rpcSRC_ISR_MALFORMED, "srcIsrMalformed", "Source issuer is malformed."); - add (rpcSRC_MISSING, "srcMissing", "Source is missing."); - add (rpcSRC_UNCLAIMED, "srcUnclaimed", "Source account is not claimed."); add (rpcSTREAM_MALFORMED, "malformedStream", "Stream malformed."); add (rpcTOO_BUSY, "tooBusy", "The server is too busy to help you now."); add (rpcTXN_NOT_FOUND, "txnNotFound", "Transaction not found."); add (rpcUNKNOWN_COMMAND, "unknownCmd", "Unknown method."); - add (rpcWRONG_SEED, "wrongSeed", "The regular key does not point as the master key."); add (rpcSENDMAX_MALFORMED, "sendMaxMalformed", "SendMax amount malformed."); + + // Verify that the number of entries in m_map equals the number of + // enums that have descriptions. That skips rpcUNKNOWN and rpcSUCCESS, + // which are -1 and 0 respectively. + assert (safe_cast(rpcLAST) == m_map.size()); } ErrorInfo const& get (error_code_i code) const { - Map::const_iterator const iter (m_map.find (code)); + Map::const_iterator const iter {m_map.find (code)}; assert (iter != m_map.end()); if (iter != m_map.end()) return iter->second; @@ -139,17 +126,18 @@ private: void add (error_code_i code, std::string const& token, std::string const& message) { - std::pair result ( + std::pair const result { m_map.emplace (std::piecewise_construct, std::forward_as_tuple (code), std::forward_as_tuple ( - code, token, message))); + code, token, message))}; + if (! result.second) Throw ("duplicate error code"); } private: Map m_map; - ErrorInfo m_unknown; + ErrorInfo const m_unknown; }; } @@ -158,7 +146,7 @@ private: ErrorInfo const& get_error_info (error_code_i code) { - static detail::ErrorCategory category; + static detail::ErrorCategory const category; return category.get (code); }