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