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 ripple {
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
212template <class JsonValue>
213void
214inject_error(error_code_i code, JsonValue& json)
215{
216 ErrorInfo const& info(get_error_info(code));
217 json[jss::error] = info.token;
218 json[jss::error_code] = info.code;
219 json[jss::error_message] = info.message;
220}
221
222template <class JsonValue>
223void
224inject_error(int code, JsonValue& json)
225{
226 inject_error(error_code_i(code), json);
227}
228
229template <class JsonValue>
230void
231inject_error(error_code_i code, std::string const& message, JsonValue& json)
232{
233 ErrorInfo const& info(get_error_info(code));
234 json[jss::error] = info.token;
235 json[jss::error_code] = info.code;
236 json[jss::error_message] = message;
237}
238
246make_error(error_code_i code, std::string const& message);
251inline Json::Value
253{
254 return make_error(rpcINVALID_PARAMS, message);
255}
256
257inline std::string
259{
260 return "Missing field '" + name + "'.";
261}
262
263inline Json::Value
268
269inline Json::Value
274
275inline std::string
277{
278 return "Invalid field '" + name + "', not object.";
279}
280
281inline Json::Value
283{
285}
286
287inline Json::Value
292
293inline std::string
295{
296 return "Invalid field '" + name + "'.";
297}
298
299inline std::string
304
305inline Json::Value
310
311inline Json::Value
316
317inline std::string
319{
320 return "Invalid field '" + name + "', not " + type + ".";
321}
322
323inline std::string
325{
326 return expected_field_message(std::string(name), type);
327}
328
329inline Json::Value
331{
332 return make_param_error(expected_field_message(name, type));
333}
334
335inline Json::Value
337{
338 return expected_field_error(std::string(name), type);
339}
340
341inline Json::Value
343{
344 return make_param_error("not a validator");
345}
346
350bool
351contains_error(Json::Value const& json);
352
354int
356
357} // namespace RPC
358
361rpcErrorString(Json::Value const& jv);
362
363} // namespace ripple
364
365#endif
Lightweight wrapper to tag static string.
Definition json_value.h:45
Represents a JSON value.
Definition json_value.h:131
bool contains_error(Json::Value const &json)
Returns true if the json contains an rpc error specification.
Json::Value make_error(error_code_i code)
Returns a new json object that reflects the error code.
Json::Value invalid_field_error(std::string const &name)
Definition ErrorCodes.h:306
void inject_error(error_code_i code, JsonValue &json)
Add or update the json update to reflect the error code.
Definition ErrorCodes.h:214
Json::Value make_param_error(std::string const &message)
Returns a new json object that indicates invalid parameters.
Definition ErrorCodes.h:252
std::string missing_field_message(std::string const &name)
Definition ErrorCodes.h:258
Json::Value not_validator_error()
Definition ErrorCodes.h:342
int error_code_http_status(error_code_i code)
Returns http status that corresponds to the error code.
std::string invalid_field_message(std::string const &name)
Definition ErrorCodes.h:294
std::string expected_field_message(std::string const &name, std::string const &type)
Definition ErrorCodes.h:318
Json::Value object_field_error(std::string const &name)
Definition ErrorCodes.h:282
std::string object_field_message(std::string const &name)
Definition ErrorCodes.h:276
ErrorInfo const & get_error_info(error_code_i code)
Returns an ErrorInfo that reflects the error code.
Json::Value expected_field_error(std::string const &name, std::string const &type)
Definition ErrorCodes.h:330
Json::Value missing_field_error(std::string const &name)
Definition ErrorCodes.h:264
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.
@ rpcNO_EVENTS
Definition ErrorCodes.h:35
@ rpcACT_NOT_FOUND
Definition ErrorCodes.h:51
@ rpcDST_ACT_MISSING
Definition ErrorCodes.h:85
@ rpcBAD_ISSUER
Definition ErrorCodes.h:77
@ rpcNOT_SUPPORTED
Definition ErrorCodes.h:113
@ rpcALREADY_SINGLE_SIG
Definition ErrorCodes.h:73
@ rpcNO_NETWORK
Definition ErrorCodes.h:47
@ rpcISSUE_MALFORMED
Definition ErrorCodes.h:127
@ rpcEXCESSIVE_LGR_RANGE
Definition ErrorCodes.h:116
@ rpcATX_DEPRECATED
Definition ErrorCodes.h:108
@ rpcORACLE_MALFORMED
Definition ErrorCodes.h:130
@ rpcAMENDMENT_BLOCKED
Definition ErrorCodes.h:42
@ rpcINVALID_LGR_RANGE
Definition ErrorCodes.h:117
@ rpcUNKNOWN_COMMAND
Definition ErrorCodes.h:66
@ rpcTXN_NOT_FOUND
Definition ErrorCodes.h:61
@ rpcLGR_NOT_VALIDATED
Definition ErrorCodes.h:54
@ rpcTOO_BUSY
Definition ErrorCodes.h:37
@ rpcSRC_ACT_NOT_FOUND
Definition ErrorCodes.h:103
@ rpcDELEGATE_ACT_NOT_FOUND
Definition ErrorCodes.h:104
@ rpcENTRY_NOT_FOUND
Definition ErrorCodes.h:142
@ rpcTX_SIGNED
Definition ErrorCodes.h:136
@ rpcACT_MALFORMED
Definition ErrorCodes.h:71
@ rpcSLOW_DOWN
Definition ErrorCodes.h:38
@ rpcMASTER_DISABLED
Definition ErrorCodes.h:55
@ rpcBAD_FEATURE
Definition ErrorCodes.h:76
@ rpcBAD_KEY_TYPE
Definition ErrorCodes.h:114
@ rpcCHANNEL_AMT_MALFORMED
Definition ErrorCodes.h:82
@ rpcALREADY_MULTISIG
Definition ErrorCodes.h:72
@ rpcBAD_MARKET
Definition ErrorCodes.h:78
@ rpcOBJECT_NOT_FOUND
Definition ErrorCodes.h:124
@ rpcNOT_READY
Definition ErrorCodes.h:41
@ rpcSUCCESS
Definition ErrorCodes.h:25
@ rpcSENDMAX_MALFORMED
Definition ErrorCodes.h:100
@ rpcNO_CURRENT
Definition ErrorCodes.h:46
@ rpcPUBLIC_MALFORMED
Definition ErrorCodes.h:98
@ rpcEXPIRED_VALIDATOR_LIST
Definition ErrorCodes.h:118
@ rpcDOMAIN_MALFORMED
Definition ErrorCodes.h:139
@ rpcDST_ISR_MALFORMED
Definition ErrorCodes.h:89
@ rpcBAD_CREDENTIALS
Definition ErrorCodes.h:133
@ rpcINVALID_PARAMS
Definition ErrorCodes.h:65
@ rpcINTERNAL
Definition ErrorCodes.h:111
@ rpcBAD_SECRET
Definition ErrorCodes.h:79
@ rpcBAD_SYNTAX
Definition ErrorCodes.h:27
@ rpcSTREAM_MALFORMED
Definition ErrorCodes.h:107
@ rpcLGR_NOT_FOUND
Definition ErrorCodes.h:53
@ rpcLGR_IDXS_INVALID
Definition ErrorCodes.h:93
@ rpcSRC_ACT_MALFORMED
Definition ErrorCodes.h:101
@ rpcNOT_IMPL
Definition ErrorCodes.h:112
@ rpcSRC_ISR_MALFORMED
Definition ErrorCodes.h:106
@ rpcSIGNING_MALFORMED
Definition ErrorCodes.h:99
@ rpcUNKNOWN
Definition ErrorCodes.h:23
@ rpcCHANNEL_MALFORMED
Definition ErrorCodes.h:81
@ rpcNO_PF_REQUEST
Definition ErrorCodes.h:67
@ rpcDST_AMT_MALFORMED
Definition ErrorCodes.h:87
@ rpcLGR_IDX_MALFORMED
Definition ErrorCodes.h:94
@ rpcCOMMAND_MISSING
Definition ErrorCodes.h:83
@ rpcFORBIDDEN
Definition ErrorCodes.h:29
@ rpcNO_CLOSED
Definition ErrorCodes.h:45
@ rpcJSON_RPC
Definition ErrorCodes.h:28
@ rpcNOT_ENABLED
Definition ErrorCodes.h:40
@ rpcDST_ACT_MALFORMED
Definition ErrorCodes.h:84
@ rpcWRONG_NETWORK
Definition ErrorCodes.h:31
@ rpcUNEXPECTED_LEDGER_TYPE
Definition ErrorCodes.h:143
@ rpcSRC_CUR_MALFORMED
Definition ErrorCodes.h:105
@ rpcINVALID_HOTWALLET
Definition ErrorCodes.h:62
@ rpcBAD_SEED
Definition ErrorCodes.h:80
@ rpcDST_AMT_MISSING
Definition ErrorCodes.h:88
@ rpcHIGH_FEE
Definition ErrorCodes.h:39
@ rpcREPORTING_UNSUPPORTED
Definition ErrorCodes.h:122
@ rpcDB_DESERIALIZATION
Definition ErrorCodes.h:115
@ rpcDST_ACT_NOT_FOUND
Definition ErrorCodes.h:86
@ rpcNOT_SYNCED
Definition ErrorCodes.h:48
@ rpcNO_PERMISSION
Definition ErrorCodes.h:34
@ rpcSRC_ACT_MISSING
Definition ErrorCodes.h:102
warning_code_i
Codes returned in the warnings array of certain RPC commands.
Definition ErrorCodes.h:153
@ warnRPC_EXPIRED_VALIDATOR_LIST
Definition ErrorCodes.h:156
@ warnRPC_FIELDS_DEPRECATED
Definition ErrorCodes.h:158
@ warnRPC_UNSUPPORTED_MAJORITY
Definition ErrorCodes.h:154
@ warnRPC_AMENDMENT_BLOCKED
Definition ErrorCodes.h:155
Maps an rpc error code to its token, default message, and HTTP status.
Definition ErrorCodes.h:170
constexpr ErrorInfo(error_code_i code_, char const *token_, char const *message_)
Definition ErrorCodes.h:180
Json::StaticString message
Definition ErrorCodes.h:202
Json::StaticString token
Definition ErrorCodes.h:201
constexpr ErrorInfo(error_code_i code_, char const *token_, char const *message_, int http_status_)
Definition ErrorCodes.h:188