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 rpcLAST = rpcDOMAIN_MALFORMED // rpcLAST should always equal the last code.
162
171 // unused = 1004
172};
173
174//------------------------------------------------------------------------------
175
176// VFALCO NOTE these should probably not be in the RPC namespace.
177
178namespace RPC {
179
182{
183 // Default ctor needed to produce an empty std::array during constexpr eval.
184 constexpr ErrorInfo()
186 , token("unknown")
187 , message("An unknown error code.")
188 , http_status(200)
189 {
190 }
191
192 constexpr ErrorInfo(
193 error_code_i code_,
194 char const* token_,
195 char const* message_)
196 : code(code_), token(token_), message(message_), http_status(200)
197 {
198 }
199
200 constexpr ErrorInfo(
201 error_code_i code_,
202 char const* token_,
203 char const* message_,
204 int http_status_)
205 : code(code_)
206 , token(token_)
207 , message(message_)
208 , http_status(http_status_)
209 {
210 }
211
216};
217
219ErrorInfo const&
221
224template <class JsonValue>
225void
226inject_error(error_code_i code, JsonValue& json)
227{
228 ErrorInfo const& info(get_error_info(code));
229 json[jss::error] = info.token;
230 json[jss::error_code] = info.code;
231 json[jss::error_message] = info.message;
232}
233
234template <class JsonValue>
235void
236inject_error(int code, JsonValue& json)
237{
238 inject_error(error_code_i(code), json);
239}
240
241template <class JsonValue>
242void
243inject_error(error_code_i code, std::string const& message, JsonValue& json)
244{
245 ErrorInfo const& info(get_error_info(code));
246 json[jss::error] = info.token;
247 json[jss::error_code] = info.code;
248 json[jss::error_message] = message;
249}
250
258make_error(error_code_i code, std::string const& message);
263inline Json::Value
265{
266 return make_error(rpcINVALID_PARAMS, message);
267}
268
269inline std::string
271{
272 return "Missing field '" + name + "'.";
273}
274
275inline Json::Value
277{
279}
280
281inline Json::Value
283{
284 return missing_field_error(std::string(name));
285}
286
287inline std::string
289{
290 return "Invalid field '" + name + "', not object.";
291}
292
293inline Json::Value
295{
297}
298
299inline Json::Value
301{
302 return object_field_error(std::string(name));
303}
304
305inline std::string
307{
308 return "Invalid field '" + name + "'.";
309}
310
311inline std::string
313{
315}
316
317inline Json::Value
319{
321}
322
323inline Json::Value
325{
326 return invalid_field_error(std::string(name));
327}
328
329inline std::string
331{
332 return "Invalid field '" + name + "', not " + type + ".";
333}
334
335inline std::string
337{
338 return expected_field_message(std::string(name), type);
339}
340
341inline Json::Value
343{
344 return make_param_error(expected_field_message(name, type));
345}
346
347inline Json::Value
349{
350 return expected_field_error(std::string(name), type);
351}
352
353inline Json::Value
355{
356 return make_param_error("not a validator");
357}
358
362bool
363contains_error(Json::Value const& json);
364
366int
368
369} // namespace RPC
370
373rpcErrorString(Json::Value const& jv);
374
375} // namespace ripple
376
377#endif
Lightweight wrapper to tag static string.
Definition: json_value.h:64
Represents a JSON value.
Definition: json_value.h:150
bool contains_error(Json::Value const &json)
Returns true if the json contains an rpc error specification.
Definition: ErrorCodes.cpp:204
Json::Value make_error(error_code_i code)
Returns a new json object that reflects the error code.
Definition: ErrorCodes.cpp:188
Json::Value invalid_field_error(std::string const &name)
Definition: ErrorCodes.h:318
void inject_error(error_code_i code, JsonValue &json)
Add or update the json update to reflect the error code.
Definition: ErrorCodes.h:226
Json::Value make_param_error(std::string const &message)
Returns a new json object that indicates invalid parameters.
Definition: ErrorCodes.h:264
std::string missing_field_message(std::string const &name)
Definition: ErrorCodes.h:270
Json::Value not_validator_error()
Definition: ErrorCodes.h:354
int error_code_http_status(error_code_i code)
Returns http status that corresponds to the error code.
Definition: ErrorCodes.cpp:212
std::string invalid_field_message(std::string const &name)
Definition: ErrorCodes.h:306
std::string expected_field_message(std::string const &name, std::string const &type)
Definition: ErrorCodes.h:330
Json::Value object_field_error(std::string const &name)
Definition: ErrorCodes.h:294
std::string object_field_message(std::string const &name)
Definition: ErrorCodes.h:288
ErrorInfo const & get_error_info(error_code_i code)
Returns an ErrorInfo that reflects the error code.
Definition: ErrorCodes.cpp:180
Json::Value expected_field_error(std::string const &name, std::string const &type)
Definition: ErrorCodes.h:342
Json::Value missing_field_error(std::string const &name)
Definition: ErrorCodes.h:276
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:220
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:160
@ 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
@ 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
@ 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:167
@ warnRPC_EXPIRED_VALIDATOR_LIST
Definition: ErrorCodes.h:170
@ warnRPC_UNSUPPORTED_MAJORITY
Definition: ErrorCodes.h:168
@ warnRPC_AMENDMENT_BLOCKED
Definition: ErrorCodes.h:169
Maps an rpc error code to its token, default message, and HTTP status.
Definition: ErrorCodes.h:182
constexpr ErrorInfo()
Definition: ErrorCodes.h:184
constexpr ErrorInfo(error_code_i code_, char const *token_, char const *message_)
Definition: ErrorCodes.h:192
Json::StaticString message
Definition: ErrorCodes.h:214
Json::StaticString token
Definition: ErrorCodes.h:213
constexpr ErrorInfo(error_code_i code_, char const *token_, char const *message_, int http_status_)
Definition: ErrorCodes.h:200