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,
123 // unused 68,
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 rpcLAST = rpcBAD_CREDENTIALS // rpcLAST should always equal the last code.
156
165 // unused = 1004
166};
167
168//------------------------------------------------------------------------------
169
170// VFALCO NOTE these should probably not be in the RPC namespace.
171
172namespace RPC {
173
176{
177 // Default ctor needed to produce an empty std::array during constexpr eval.
178 constexpr ErrorInfo()
180 , token("unknown")
181 , message("An unknown error code.")
182 , http_status(200)
183 {
184 }
185
186 constexpr ErrorInfo(
187 error_code_i code_,
188 char const* token_,
189 char const* message_)
190 : code(code_), token(token_), message(message_), http_status(200)
191 {
192 }
193
194 constexpr ErrorInfo(
195 error_code_i code_,
196 char const* token_,
197 char const* message_,
198 int http_status_)
199 : code(code_)
200 , token(token_)
201 , message(message_)
202 , http_status(http_status_)
203 {
204 }
205
210};
211
213ErrorInfo const&
215
218template <class JsonValue>
219void
220inject_error(error_code_i code, JsonValue& json)
221{
222 ErrorInfo const& info(get_error_info(code));
223 json[jss::error] = info.token;
224 json[jss::error_code] = info.code;
225 json[jss::error_message] = info.message;
226}
227
228template <class JsonValue>
229void
230inject_error(int code, JsonValue& json)
231{
232 inject_error(error_code_i(code), json);
233}
234
235template <class JsonValue>
236void
237inject_error(error_code_i code, std::string const& message, JsonValue& json)
238{
239 ErrorInfo const& info(get_error_info(code));
240 json[jss::error] = info.token;
241 json[jss::error_code] = info.code;
242 json[jss::error_message] = message;
243}
244
252make_error(error_code_i code, std::string const& message);
257inline Json::Value
259{
260 return make_error(rpcINVALID_PARAMS, message);
261}
262
263inline std::string
265{
266 return "Missing field '" + name + "'.";
267}
268
269inline Json::Value
271{
273}
274
275inline Json::Value
277{
278 return missing_field_error(std::string(name));
279}
280
281inline std::string
283{
284 return "Invalid field '" + name + "', not object.";
285}
286
287inline Json::Value
289{
291}
292
293inline Json::Value
295{
296 return object_field_error(std::string(name));
297}
298
299inline std::string
301{
302 return "Invalid field '" + name + "'.";
303}
304
305inline std::string
307{
309}
310
311inline Json::Value
313{
315}
316
317inline Json::Value
319{
320 return invalid_field_error(std::string(name));
321}
322
323inline std::string
325{
326 return "Invalid field '" + name + "', not " + type + ".";
327}
328
329inline std::string
331{
332 return expected_field_message(std::string(name), type);
333}
334
335inline Json::Value
337{
338 return make_param_error(expected_field_message(name, type));
339}
340
341inline Json::Value
343{
344 return expected_field_error(std::string(name), type);
345}
346
347inline Json::Value
349{
350 return make_param_error("not a validator");
351}
352
356bool
357contains_error(Json::Value const& json);
358
360int
362
363} // namespace RPC
364
367rpcErrorString(Json::Value const& jv);
368
369} // namespace ripple
370
371#endif
Lightweight wrapper to tag static string.
Definition: json_value.h:61
Represents a JSON value.
Definition: json_value.h:147
bool contains_error(Json::Value const &json)
Returns true if the json contains an rpc error specification.
Definition: ErrorCodes.cpp:196
Json::Value make_error(error_code_i code)
Returns a new json object that reflects the error code.
Definition: ErrorCodes.cpp:180
Json::Value invalid_field_error(std::string const &name)
Definition: ErrorCodes.h:312
void inject_error(error_code_i code, JsonValue &json)
Add or update the json update to reflect the error code.
Definition: ErrorCodes.h:220
Json::Value make_param_error(std::string const &message)
Returns a new json object that indicates invalid parameters.
Definition: ErrorCodes.h:258
std::string missing_field_message(std::string const &name)
Definition: ErrorCodes.h:264
Json::Value not_validator_error()
Definition: ErrorCodes.h:348
int error_code_http_status(error_code_i code)
Returns http status that corresponds to the error code.
Definition: ErrorCodes.cpp:204
std::string invalid_field_message(std::string const &name)
Definition: ErrorCodes.h:300
std::string expected_field_message(std::string const &name, std::string const &type)
Definition: ErrorCodes.h:324
Json::Value object_field_error(std::string const &name)
Definition: ErrorCodes.h:288
std::string object_field_message(std::string const &name)
Definition: ErrorCodes.h:282
ErrorInfo const & get_error_info(error_code_i code)
Returns an ErrorInfo that reflects the error code.
Definition: ErrorCodes.cpp:172
Json::Value expected_field_error(std::string const &name, std::string const &type)
Definition: ErrorCodes.h:336
Json::Value missing_field_error(std::string const &name)
Definition: ErrorCodes.h:270
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
std::string rpcErrorString(Json::Value const &jv)
Returns a single string with the contents of an RPC error.
Definition: ErrorCodes.cpp:212
error_code_i
Definition: ErrorCodes.h:40
@ 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
@ rpcLAST
Definition: ErrorCodes.h:154
@ 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
@ 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
@ 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
@ 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:161
@ warnRPC_EXPIRED_VALIDATOR_LIST
Definition: ErrorCodes.h:164
@ warnRPC_UNSUPPORTED_MAJORITY
Definition: ErrorCodes.h:162
@ warnRPC_AMENDMENT_BLOCKED
Definition: ErrorCodes.h:163
Maps an rpc error code to its token, default message, and HTTP status.
Definition: ErrorCodes.h:176
constexpr ErrorInfo()
Definition: ErrorCodes.h:178
constexpr ErrorInfo(error_code_i code_, char const *token_, char const *message_)
Definition: ErrorCodes.h:186
Json::StaticString message
Definition: ErrorCodes.h:208
Json::StaticString token
Definition: ErrorCodes.h:207
constexpr ErrorInfo(error_code_i code_, char const *token_, char const *message_, int http_status_)
Definition: ErrorCodes.h:194