rippled
Loading...
Searching...
No Matches
ErrorCodes.h
1#pragma once
2
3#include <xrpl/json/json_value.h>
4#include <xrpl/protocol/jss.h>
5
6namespace xrpl {
7
8// VFALCO NOTE These are outside the RPC namespace
9
10// NOTE: Although the precise numeric values of these codes were never
11// intended to be stable, several API endpoints include the numeric values.
12// Some users came to rely on the values, meaning that renumbering would be
13// a breaking change for those users.
14//
15// We therefore treat the range of values as stable although they are not
16// and are subject to change.
17//
18// Please only append to this table. Do not "fill-in" gaps and do not re-use
19// or repurpose error code values.
21 // -1 represents codes not listed in this enumeration
23
25
29
31 // Misc failure
32 // unused 5,
35 // unused 8,
42
43 // Networking
48
49 // Ledger state
51 // unused 20,
55 // unused 24,
56 // unused 25,
57 // unused 26,
58 // unused 27,
59 // unused 28,
62
63 // Malformed command
67
68 // Bad parameter
69 // NOT USED DO NOT USE AGAIN rpcACT_BITCOIN = 34,
73 // unused 38,
74 // unused 39,
89 // unused 54,
90 // unused 55,
91 // unused 56,
94 // unused 59,
95 // unused 60,
96 // unused 61,
108
109 // Internal error (should never happen)
110 rpcINTERNAL = 73, // Generic internal error.
118
119 // unused = 90,
120 // DEPRECATED. New code must not use this value.
122
124
125 // AMM
127
128 // Oracle
130
131 // deposit_authorized + credentials
133
134 // Simulate
136
137 // Pathfinding
139
140 // ledger_entry
143
144 rpcLAST = rpcUNEXPECTED_LEDGER_TYPE // rpcLAST should always equal the last code.
146
155 // unused = 1004
156 warnRPC_FIELDS_DEPRECATED = 2004, // rippled needs to maintain
157 // compatibility with Clio on this code.
158};
159
160//------------------------------------------------------------------------------
161
162// VFALCO NOTE these should probably not be in the RPC namespace.
163
164namespace RPC {
165
168{
169 // Default ctor needed to produce an empty std::array during constexpr eval.
170 constexpr ErrorInfo()
171 : code(rpcUNKNOWN), token("unknown"), message("An unknown error code."), http_status(200)
172 {
173 }
174
175 constexpr ErrorInfo(error_code_i code_, char const* token_, char const* message_)
176 : code(code_), token(token_), message(message_), http_status(200)
177 {
178 }
179
180 constexpr ErrorInfo(
181 error_code_i code_,
182 char const* token_,
183 char const* message_,
184 int http_status_)
185 : code(code_), token(token_), message(message_), http_status(http_status_)
186 {
187 }
188
193};
194
196ErrorInfo const&
198
201void
203
204void
205inject_error(error_code_i code, std::string const& message, Json::Value& json);
213make_error(error_code_i code, std::string const& message);
218inline Json::Value
220{
221 return make_error(rpcINVALID_PARAMS, message);
222}
223
224inline std::string
226{
227 return "Missing field '" + name + "'.";
228}
229
230inline Json::Value
235
236inline Json::Value
241
242inline std::string
244{
245 return "Invalid field '" + name + "', not object.";
246}
247
248inline Json::Value
250{
252}
253
254inline Json::Value
259
260inline std::string
262{
263 return "Invalid field '" + name + "'.";
264}
265
266inline std::string
271
272inline Json::Value
277
278inline Json::Value
283
284inline std::string
286{
287 return "Invalid field '" + name + "', not " + type + ".";
288}
289
290inline std::string
292{
293 return expected_field_message(std::string(name), type);
294}
295
296inline Json::Value
298{
299 return make_param_error(expected_field_message(name, type));
300}
301
302inline Json::Value
304{
305 return expected_field_error(std::string(name), type);
306}
307
308inline Json::Value
310{
311 return make_param_error("not a validator");
312}
313
317bool
318contains_error(Json::Value const& json);
319
321int
323
324} // namespace RPC
325
328rpcErrorString(Json::Value const& jv);
329
330} // namespace xrpl
Lightweight wrapper to tag static string.
Definition json_value.h:44
Represents a JSON value.
Definition json_value.h:130
Json::Value invalid_field_error(std::string const &name)
Definition ErrorCodes.h:273
std::string expected_field_message(std::string const &name, std::string const &type)
Definition ErrorCodes.h:285
int error_code_http_status(error_code_i code)
Returns http status that corresponds to the error code.
std::string missing_field_message(std::string const &name)
Definition ErrorCodes.h:225
Json::Value expected_field_error(std::string const &name, std::string const &type)
Definition ErrorCodes.h:297
Json::Value missing_field_error(std::string const &name)
Definition ErrorCodes.h:231
Json::Value object_field_error(std::string const &name)
Definition ErrorCodes.h:249
ErrorInfo const & get_error_info(error_code_i code)
Returns an ErrorInfo that reflects the error code.
std::string object_field_message(std::string const &name)
Definition ErrorCodes.h:243
Json::Value not_validator_error()
Definition ErrorCodes.h:309
Json::Value make_param_error(std::string const &message)
Returns a new json object that indicates invalid parameters.
Definition ErrorCodes.h:219
void inject_error(error_code_i code, Json::Value &json)
Add or update the json update to reflect the error code.
std::string invalid_field_message(std::string const &name)
Definition ErrorCodes.h:261
Json::Value make_error(error_code_i code)
Returns a new json object that reflects the error code.
bool contains_error(Json::Value const &json)
Returns true if the json contains an rpc error specification.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
std::string rpcErrorString(Json::Value const &jv)
Returns a single string with the contents of an RPC error.
error_code_i
Definition ErrorCodes.h:20
@ rpcSRC_CUR_MALFORMED
Definition ErrorCodes.h:104
@ rpcCOMMAND_MISSING
Definition ErrorCodes.h:82
@ rpcTOO_BUSY
Definition ErrorCodes.h:36
@ rpcOBJECT_NOT_FOUND
Definition ErrorCodes.h:123
@ rpcSTREAM_MALFORMED
Definition ErrorCodes.h:106
@ rpcUNEXPECTED_LEDGER_TYPE
Definition ErrorCodes.h:142
@ rpcTXN_NOT_FOUND
Definition ErrorCodes.h:60
@ rpcLGR_NOT_FOUND
Definition ErrorCodes.h:52
@ rpcNO_NETWORK
Definition ErrorCodes.h:46
@ rpcNO_CLOSED
Definition ErrorCodes.h:44
@ rpcNO_PERMISSION
Definition ErrorCodes.h:33
@ rpcTX_SIGNED
Definition ErrorCodes.h:135
@ rpcSLOW_DOWN
Definition ErrorCodes.h:37
@ rpcBAD_CREDENTIALS
Definition ErrorCodes.h:132
@ rpcNOT_IMPL
Definition ErrorCodes.h:111
@ rpcNO_CURRENT
Definition ErrorCodes.h:45
@ rpcISSUE_MALFORMED
Definition ErrorCodes.h:126
@ rpcBAD_MARKET
Definition ErrorCodes.h:77
@ rpcBAD_FEATURE
Definition ErrorCodes.h:75
@ rpcSENDMAX_MALFORMED
Definition ErrorCodes.h:99
@ rpcEXCESSIVE_LGR_RANGE
Definition ErrorCodes.h:115
@ rpcORACLE_MALFORMED
Definition ErrorCodes.h:129
@ rpcBAD_SYNTAX
Definition ErrorCodes.h:26
@ rpcSRC_ISR_MALFORMED
Definition ErrorCodes.h:105
@ rpcNO_PF_REQUEST
Definition ErrorCodes.h:66
@ rpcCHANNEL_AMT_MALFORMED
Definition ErrorCodes.h:81
@ rpcDELEGATE_ACT_NOT_FOUND
Definition ErrorCodes.h:103
@ rpcSIGNING_MALFORMED
Definition ErrorCodes.h:98
@ rpcDST_AMT_MISSING
Definition ErrorCodes.h:87
@ rpcHIGH_FEE
Definition ErrorCodes.h:38
@ rpcDST_ACT_MISSING
Definition ErrorCodes.h:84
@ rpcNO_EVENTS
Definition ErrorCodes.h:34
@ rpcPUBLIC_MALFORMED
Definition ErrorCodes.h:97
@ rpcNOT_ENABLED
Definition ErrorCodes.h:39
@ rpcLAST
Definition ErrorCodes.h:144
@ rpcLGR_NOT_VALIDATED
Definition ErrorCodes.h:53
@ rpcBAD_KEY_TYPE
Definition ErrorCodes.h:113
@ rpcAMENDMENT_BLOCKED
Definition ErrorCodes.h:41
@ rpcMASTER_DISABLED
Definition ErrorCodes.h:54
@ rpcINTERNAL
Definition ErrorCodes.h:110
@ rpcDST_AMT_MALFORMED
Definition ErrorCodes.h:86
@ rpcFORBIDDEN
Definition ErrorCodes.h:28
@ rpcCHANNEL_MALFORMED
Definition ErrorCodes.h:80
@ rpcDB_DESERIALIZATION
Definition ErrorCodes.h:114
@ rpcALREADY_SINGLE_SIG
Definition ErrorCodes.h:72
@ rpcLGR_IDX_MALFORMED
Definition ErrorCodes.h:93
@ rpcUNKNOWN_COMMAND
Definition ErrorCodes.h:65
@ rpcSRC_ACT_NOT_FOUND
Definition ErrorCodes.h:102
@ rpcSRC_ACT_MALFORMED
Definition ErrorCodes.h:100
@ rpcNOT_SUPPORTED
Definition ErrorCodes.h:112
@ rpcLGR_IDXS_INVALID
Definition ErrorCodes.h:92
@ rpcEXPIRED_VALIDATOR_LIST
Definition ErrorCodes.h:117
@ rpcNOT_SYNCED
Definition ErrorCodes.h:47
@ rpcACT_NOT_FOUND
Definition ErrorCodes.h:50
@ rpcREPORTING_UNSUPPORTED
Definition ErrorCodes.h:121
@ rpcBAD_SEED
Definition ErrorCodes.h:79
@ rpcATX_DEPRECATED
Definition ErrorCodes.h:107
@ rpcWRONG_NETWORK
Definition ErrorCodes.h:30
@ rpcDOMAIN_MALFORMED
Definition ErrorCodes.h:138
@ rpcJSON_RPC
Definition ErrorCodes.h:27
@ rpcDST_ACT_MALFORMED
Definition ErrorCodes.h:83
@ rpcINVALID_HOTWALLET
Definition ErrorCodes.h:61
@ rpcDST_ACT_NOT_FOUND
Definition ErrorCodes.h:85
@ rpcENTRY_NOT_FOUND
Definition ErrorCodes.h:141
@ rpcUNKNOWN
Definition ErrorCodes.h:22
@ rpcDST_ISR_MALFORMED
Definition ErrorCodes.h:88
@ rpcBAD_ISSUER
Definition ErrorCodes.h:76
@ rpcINVALID_PARAMS
Definition ErrorCodes.h:64
@ rpcSRC_ACT_MISSING
Definition ErrorCodes.h:101
@ rpcBAD_SECRET
Definition ErrorCodes.h:78
@ rpcACT_MALFORMED
Definition ErrorCodes.h:70
@ rpcALREADY_MULTISIG
Definition ErrorCodes.h:71
@ rpcINVALID_LGR_RANGE
Definition ErrorCodes.h:116
@ rpcNOT_READY
Definition ErrorCodes.h:40
@ rpcSUCCESS
Definition ErrorCodes.h:24
warning_code_i
Codes returned in the warnings array of certain RPC commands.
Definition ErrorCodes.h:151
@ warnRPC_AMENDMENT_BLOCKED
Definition ErrorCodes.h:153
@ warnRPC_UNSUPPORTED_MAJORITY
Definition ErrorCodes.h:152
@ warnRPC_FIELDS_DEPRECATED
Definition ErrorCodes.h:156
@ warnRPC_EXPIRED_VALIDATOR_LIST
Definition ErrorCodes.h:154
Maps an rpc error code to its token, default message, and HTTP status.
Definition ErrorCodes.h:168
error_code_i code
Definition ErrorCodes.h:189
Json::StaticString token
Definition ErrorCodes.h:190
constexpr ErrorInfo()
Definition ErrorCodes.h:170
constexpr ErrorInfo(error_code_i code_, char const *token_, char const *message_, int http_status_)
Definition ErrorCodes.h:180
constexpr ErrorInfo(error_code_i code_, char const *token_, char const *message_)
Definition ErrorCodes.h:175
Json::StaticString message
Definition ErrorCodes.h:191