rippled
Loading...
Searching...
No Matches
ErrorCodes.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012 - 2019 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#ifndef RIPPLE_PROTOCOL_ERRORCODES_H_INCLUDED
21#define RIPPLE_PROTOCOL_ERRORCODES_H_INCLUDED
22
23#include <xrpl/json/json_value.h>
24#include <xrpl/protocol/jss.h>
25
26namespace ripple {
27
28// VFALCO NOTE These are outside the RPC namespace
29
30// NOTE: Although the precise numeric values of these codes were never
31// intended to be stable, several API endpoints include the numeric values.
32// Some users came to rely on the values, meaning that renumbering would be
33// a breaking change for those users.
34//
35// We therefore treat the range of values as stable although they are not
36// and are subject to change.
37//
38// Please only append to this table. Do not "fill-in" gaps and do not re-use
39// or repurpose error code values.
41 // -1 represents codes not listed in this enumeration
43
45
49
51 // Misc failure
52 // unused 5,
55 // unused 8,
62
63 // Networking
68
69 // Ledger state
71 // unused 20,
75 // unused 24,
76 // unused 25,
77 // unused 26,
78 // unused 27,
79 // unused 28,
82
83 // Malformed command
87
88 // Bad parameter
89 // NOT USED DO NOT USE AGAIN rpcACT_BITCOIN = 34,
93 // unused 38,
94 // unused 39,
109 // unused 54,
110 // unused 55,
111 // unused 56,
114 // unused 59,
115 // unused 60,
116 // unused 61,
128
129 // Internal error (should never happen)
130 rpcINTERNAL = 73, // Generic internal error.
138
139 // unused = 90,
140 // DEPRECATED. New code must not use this value.
142
144
145 // AMM
147
148 // Oracle
150
151 // deposit_authorized + credentials
153
154 // Simulate
156
157 // Pathfinding
159
160 // ledger_entry
163
164 rpcLAST =
165 rpcUNEXPECTED_LEDGER_TYPE // rpcLAST should always equal the last code.
167
176 // unused = 1004
177 warnRPC_FIELDS_DEPRECATED = 2004, // rippled needs to maintain
178 // compatibility with Clio on this code.
179};
180
181//------------------------------------------------------------------------------
182
183// VFALCO NOTE these should probably not be in the RPC namespace.
184
185namespace RPC {
186
189{
190 // Default ctor needed to produce an empty std::array during constexpr eval.
191 constexpr ErrorInfo()
193 , token("unknown")
194 , message("An unknown error code.")
195 , http_status(200)
196 {
197 }
198
199 constexpr ErrorInfo(
200 error_code_i code_,
201 char const* token_,
202 char const* message_)
203 : code(code_), token(token_), message(message_), http_status(200)
204 {
205 }
206
207 constexpr ErrorInfo(
208 error_code_i code_,
209 char const* token_,
210 char const* message_,
211 int http_status_)
212 : code(code_)
213 , token(token_)
214 , message(message_)
215 , http_status(http_status_)
216 {
217 }
218
223};
224
226ErrorInfo const&
228
231template <class JsonValue>
232void
233inject_error(error_code_i code, JsonValue& json)
234{
235 ErrorInfo const& info(get_error_info(code));
236 json[jss::error] = info.token;
237 json[jss::error_code] = info.code;
238 json[jss::error_message] = info.message;
239}
240
241template <class JsonValue>
242void
243inject_error(int code, JsonValue& json)
244{
245 inject_error(error_code_i(code), json);
246}
247
248template <class JsonValue>
249void
250inject_error(error_code_i code, std::string const& message, JsonValue& json)
251{
252 ErrorInfo const& info(get_error_info(code));
253 json[jss::error] = info.token;
254 json[jss::error_code] = info.code;
255 json[jss::error_message] = message;
256}
257
265make_error(error_code_i code, std::string const& message);
270inline Json::Value
272{
273 return make_error(rpcINVALID_PARAMS, message);
274}
275
276inline std::string
278{
279 return "Missing field '" + name + "'.";
280}
281
282inline Json::Value
287
288inline Json::Value
293
294inline std::string
296{
297 return "Invalid field '" + name + "', not object.";
298}
299
300inline Json::Value
302{
304}
305
306inline Json::Value
311
312inline std::string
314{
315 return "Invalid field '" + name + "'.";
316}
317
318inline std::string
323
324inline Json::Value
329
330inline Json::Value
335
336inline std::string
338{
339 return "Invalid field '" + name + "', not " + type + ".";
340}
341
342inline std::string
344{
345 return expected_field_message(std::string(name), type);
346}
347
348inline Json::Value
350{
351 return make_param_error(expected_field_message(name, type));
352}
353
354inline Json::Value
356{
357 return expected_field_error(std::string(name), type);
358}
359
360inline Json::Value
362{
363 return make_param_error("not a validator");
364}
365
369bool
370contains_error(Json::Value const& json);
371
373int
375
376} // namespace RPC
377
380rpcErrorString(Json::Value const& jv);
381
382} // namespace ripple
383
384#endif
Lightweight wrapper to tag static string.
Definition json_value.h:63
Represents a JSON value.
Definition json_value.h:149
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:325
void inject_error(error_code_i code, JsonValue &json)
Add or update the json update to reflect the error code.
Definition ErrorCodes.h:233
Json::Value make_param_error(std::string const &message)
Returns a new json object that indicates invalid parameters.
Definition ErrorCodes.h:271
std::string missing_field_message(std::string const &name)
Definition ErrorCodes.h:277
Json::Value not_validator_error()
Definition ErrorCodes.h:361
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:313
std::string expected_field_message(std::string const &name, std::string const &type)
Definition ErrorCodes.h:337
Json::Value object_field_error(std::string const &name)
Definition ErrorCodes.h:301
std::string object_field_message(std::string const &name)
Definition ErrorCodes.h:295
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:349
Json::Value missing_field_error(std::string const &name)
Definition ErrorCodes.h:283
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
std::string rpcErrorString(Json::Value const &jv)
Returns a single string with the contents of an RPC error.
@ rpcNO_EVENTS
Definition ErrorCodes.h:54
@ rpcACT_NOT_FOUND
Definition ErrorCodes.h:70
@ rpcDST_ACT_MISSING
Definition ErrorCodes.h:104
@ rpcBAD_ISSUER
Definition ErrorCodes.h:96
@ rpcNOT_SUPPORTED
Definition ErrorCodes.h:132
@ rpcALREADY_SINGLE_SIG
Definition ErrorCodes.h:92
@ rpcNO_NETWORK
Definition ErrorCodes.h:66
@ rpcISSUE_MALFORMED
Definition ErrorCodes.h:146
@ rpcEXCESSIVE_LGR_RANGE
Definition ErrorCodes.h:135
@ rpcATX_DEPRECATED
Definition ErrorCodes.h:127
@ rpcORACLE_MALFORMED
Definition ErrorCodes.h:149
@ rpcAMENDMENT_BLOCKED
Definition ErrorCodes.h:61
@ rpcINVALID_LGR_RANGE
Definition ErrorCodes.h:136
@ rpcUNKNOWN_COMMAND
Definition ErrorCodes.h:85
@ rpcTXN_NOT_FOUND
Definition ErrorCodes.h:80
@ rpcLGR_NOT_VALIDATED
Definition ErrorCodes.h:73
@ rpcTOO_BUSY
Definition ErrorCodes.h:56
@ rpcSRC_ACT_NOT_FOUND
Definition ErrorCodes.h:122
@ rpcDELEGATE_ACT_NOT_FOUND
Definition ErrorCodes.h:123
@ rpcENTRY_NOT_FOUND
Definition ErrorCodes.h:161
@ rpcTX_SIGNED
Definition ErrorCodes.h:155
@ rpcACT_MALFORMED
Definition ErrorCodes.h:90
@ rpcSLOW_DOWN
Definition ErrorCodes.h:57
@ rpcMASTER_DISABLED
Definition ErrorCodes.h:74
@ rpcBAD_FEATURE
Definition ErrorCodes.h:95
@ rpcBAD_KEY_TYPE
Definition ErrorCodes.h:133
@ rpcCHANNEL_AMT_MALFORMED
Definition ErrorCodes.h:101
@ rpcALREADY_MULTISIG
Definition ErrorCodes.h:91
@ rpcBAD_MARKET
Definition ErrorCodes.h:97
@ rpcOBJECT_NOT_FOUND
Definition ErrorCodes.h:143
@ rpcNOT_READY
Definition ErrorCodes.h:60
@ rpcSUCCESS
Definition ErrorCodes.h:44
@ rpcSENDMAX_MALFORMED
Definition ErrorCodes.h:119
@ rpcNO_CURRENT
Definition ErrorCodes.h:65
@ rpcPUBLIC_MALFORMED
Definition ErrorCodes.h:117
@ rpcEXPIRED_VALIDATOR_LIST
Definition ErrorCodes.h:137
@ rpcDOMAIN_MALFORMED
Definition ErrorCodes.h:158
@ rpcDST_ISR_MALFORMED
Definition ErrorCodes.h:108
@ rpcBAD_CREDENTIALS
Definition ErrorCodes.h:152
@ rpcINVALID_PARAMS
Definition ErrorCodes.h:84
@ rpcINTERNAL
Definition ErrorCodes.h:130
@ rpcBAD_SECRET
Definition ErrorCodes.h:98
@ rpcBAD_SYNTAX
Definition ErrorCodes.h:46
@ rpcSTREAM_MALFORMED
Definition ErrorCodes.h:126
@ rpcLGR_NOT_FOUND
Definition ErrorCodes.h:72
@ rpcLGR_IDXS_INVALID
Definition ErrorCodes.h:112
@ rpcSRC_ACT_MALFORMED
Definition ErrorCodes.h:120
@ rpcNOT_IMPL
Definition ErrorCodes.h:131
@ rpcSRC_ISR_MALFORMED
Definition ErrorCodes.h:125
@ rpcSIGNING_MALFORMED
Definition ErrorCodes.h:118
@ rpcUNKNOWN
Definition ErrorCodes.h:42
@ rpcCHANNEL_MALFORMED
Definition ErrorCodes.h:100
@ rpcNO_PF_REQUEST
Definition ErrorCodes.h:86
@ rpcDST_AMT_MALFORMED
Definition ErrorCodes.h:106
@ rpcLGR_IDX_MALFORMED
Definition ErrorCodes.h:113
@ rpcCOMMAND_MISSING
Definition ErrorCodes.h:102
@ rpcFORBIDDEN
Definition ErrorCodes.h:48
@ rpcNO_CLOSED
Definition ErrorCodes.h:64
@ rpcJSON_RPC
Definition ErrorCodes.h:47
@ rpcNOT_ENABLED
Definition ErrorCodes.h:59
@ rpcDST_ACT_MALFORMED
Definition ErrorCodes.h:103
@ rpcWRONG_NETWORK
Definition ErrorCodes.h:50
@ rpcUNEXPECTED_LEDGER_TYPE
Definition ErrorCodes.h:162
@ rpcSRC_CUR_MALFORMED
Definition ErrorCodes.h:124
@ rpcINVALID_HOTWALLET
Definition ErrorCodes.h:81
@ rpcBAD_SEED
Definition ErrorCodes.h:99
@ rpcDST_AMT_MISSING
Definition ErrorCodes.h:107
@ rpcHIGH_FEE
Definition ErrorCodes.h:58
@ rpcREPORTING_UNSUPPORTED
Definition ErrorCodes.h:141
@ rpcDB_DESERIALIZATION
Definition ErrorCodes.h:134
@ rpcDST_ACT_NOT_FOUND
Definition ErrorCodes.h:105
@ rpcNOT_SYNCED
Definition ErrorCodes.h:67
@ rpcNO_PERMISSION
Definition ErrorCodes.h:53
@ rpcSRC_ACT_MISSING
Definition ErrorCodes.h:121
warning_code_i
Codes returned in the warnings array of certain RPC commands.
Definition ErrorCodes.h:172
@ warnRPC_EXPIRED_VALIDATOR_LIST
Definition ErrorCodes.h:175
@ warnRPC_FIELDS_DEPRECATED
Definition ErrorCodes.h:177
@ warnRPC_UNSUPPORTED_MAJORITY
Definition ErrorCodes.h:173
@ warnRPC_AMENDMENT_BLOCKED
Definition ErrorCodes.h:174
Maps an rpc error code to its token, default message, and HTTP status.
Definition ErrorCodes.h:189
constexpr ErrorInfo(error_code_i code_, char const *token_, char const *message_)
Definition ErrorCodes.h:199
Json::StaticString message
Definition ErrorCodes.h:221
Json::StaticString token
Definition ErrorCodes.h:220
constexpr ErrorInfo(error_code_i code_, char const *token_, char const *message_, int http_status_)
Definition ErrorCodes.h:207