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() : code(rpcUNKNOWN), token("unknown"), message("An unknown error code."), http_status(200)
171 {
172 }
173
174 constexpr ErrorInfo(error_code_i code_, char const* token_, char const* message_)
175 : code(code_), token(token_), message(message_), http_status(200)
176 {
177 }
178
179 constexpr ErrorInfo(error_code_i code_, char const* token_, char const* message_, int http_status_)
180 : code(code_), token(token_), message(message_), http_status(http_status_)
181 {
182 }
183
188};
189
191ErrorInfo const&
193
196void
198
199void
200inject_error(error_code_i code, std::string const& message, Json::Value& json);
208make_error(error_code_i code, std::string const& message);
213inline Json::Value
215{
216 return make_error(rpcINVALID_PARAMS, message);
217}
218
219inline std::string
221{
222 return "Missing field '" + name + "'.";
223}
224
225inline Json::Value
230
231inline Json::Value
236
237inline std::string
239{
240 return "Invalid field '" + name + "', not object.";
241}
242
243inline Json::Value
245{
247}
248
249inline Json::Value
254
255inline std::string
257{
258 return "Invalid field '" + name + "'.";
259}
260
261inline std::string
266
267inline Json::Value
272
273inline Json::Value
278
279inline std::string
281{
282 return "Invalid field '" + name + "', not " + type + ".";
283}
284
285inline std::string
287{
288 return expected_field_message(std::string(name), type);
289}
290
291inline Json::Value
293{
294 return make_param_error(expected_field_message(name, type));
295}
296
297inline Json::Value
299{
300 return expected_field_error(std::string(name), type);
301}
302
303inline Json::Value
305{
306 return make_param_error("not a validator");
307}
308
312bool
313contains_error(Json::Value const& json);
314
316int
318
319} // namespace RPC
320
323rpcErrorString(Json::Value const& jv);
324
325} // 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:268
std::string expected_field_message(std::string const &name, std::string const &type)
Definition ErrorCodes.h:280
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:220
Json::Value expected_field_error(std::string const &name, std::string const &type)
Definition ErrorCodes.h:292
Json::Value missing_field_error(std::string const &name)
Definition ErrorCodes.h:226
Json::Value object_field_error(std::string const &name)
Definition ErrorCodes.h:244
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:238
Json::Value not_validator_error()
Definition ErrorCodes.h:304
Json::Value make_param_error(std::string const &message)
Returns a new json object that indicates invalid parameters.
Definition ErrorCodes.h:214
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:256
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:184
Json::StaticString token
Definition ErrorCodes.h:185
constexpr ErrorInfo()
Definition ErrorCodes.h:170
constexpr ErrorInfo(error_code_i code_, char const *token_, char const *message_, int http_status_)
Definition ErrorCodes.h:179
constexpr ErrorInfo(error_code_i code_, char const *token_, char const *message_)
Definition ErrorCodes.h:174
Json::StaticString message
Definition ErrorCodes.h:186