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 warnRPC_FIELDS_DEPRECATED = 2004, // rippled needs to maintain
173 // compatibility with Clio on this code.
174};
175
176//------------------------------------------------------------------------------
177
178// VFALCO NOTE these should probably not be in the RPC namespace.
179
180namespace RPC {
181
184{
185 // Default ctor needed to produce an empty std::array during constexpr eval.
186 constexpr ErrorInfo()
188 , token("unknown")
189 , message("An unknown error code.")
190 , http_status(200)
191 {
192 }
193
194 constexpr ErrorInfo(
195 error_code_i code_,
196 char const* token_,
197 char const* message_)
198 : code(code_), token(token_), message(message_), http_status(200)
199 {
200 }
201
202 constexpr ErrorInfo(
203 error_code_i code_,
204 char const* token_,
205 char const* message_,
206 int http_status_)
207 : code(code_)
208 , token(token_)
209 , message(message_)
210 , http_status(http_status_)
211 {
212 }
213
218};
219
221ErrorInfo const&
223
226template <class JsonValue>
227void
228inject_error(error_code_i code, JsonValue& json)
229{
230 ErrorInfo const& info(get_error_info(code));
231 json[jss::error] = info.token;
232 json[jss::error_code] = info.code;
233 json[jss::error_message] = info.message;
234}
235
236template <class JsonValue>
237void
238inject_error(int code, JsonValue& json)
239{
240 inject_error(error_code_i(code), json);
241}
242
243template <class JsonValue>
244void
245inject_error(error_code_i code, std::string const& message, JsonValue& json)
246{
247 ErrorInfo const& info(get_error_info(code));
248 json[jss::error] = info.token;
249 json[jss::error_code] = info.code;
250 json[jss::error_message] = message;
251}
252
260make_error(error_code_i code, std::string const& message);
265inline Json::Value
267{
268 return make_error(rpcINVALID_PARAMS, message);
269}
270
271inline std::string
273{
274 return "Missing field '" + name + "'.";
275}
276
277inline Json::Value
279{
281}
282
283inline Json::Value
285{
286 return missing_field_error(std::string(name));
287}
288
289inline std::string
291{
292 return "Invalid field '" + name + "', not object.";
293}
294
295inline Json::Value
297{
299}
300
301inline Json::Value
303{
304 return object_field_error(std::string(name));
305}
306
307inline std::string
309{
310 return "Invalid field '" + name + "'.";
311}
312
313inline std::string
315{
317}
318
319inline Json::Value
321{
323}
324
325inline Json::Value
327{
328 return invalid_field_error(std::string(name));
329}
330
331inline std::string
333{
334 return "Invalid field '" + name + "', not " + type + ".";
335}
336
337inline std::string
339{
340 return expected_field_message(std::string(name), type);
341}
342
343inline Json::Value
345{
346 return make_param_error(expected_field_message(name, type));
347}
348
349inline Json::Value
351{
352 return expected_field_error(std::string(name), type);
353}
354
355inline Json::Value
357{
358 return make_param_error("not a validator");
359}
360
364bool
365contains_error(Json::Value const& json);
366
368int
370
371} // namespace RPC
372
375rpcErrorString(Json::Value const& jv);
376
377} // namespace ripple
378
379#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.
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:320
void inject_error(error_code_i code, JsonValue &json)
Add or update the json update to reflect the error code.
Definition: ErrorCodes.h:228
Json::Value make_param_error(std::string const &message)
Returns a new json object that indicates invalid parameters.
Definition: ErrorCodes.h:266
std::string missing_field_message(std::string const &name)
Definition: ErrorCodes.h:272
Json::Value not_validator_error()
Definition: ErrorCodes.h:356
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:308
std::string expected_field_message(std::string const &name, std::string const &type)
Definition: ErrorCodes.h:332
Json::Value object_field_error(std::string const &name)
Definition: ErrorCodes.h:296
std::string object_field_message(std::string const &name)
Definition: ErrorCodes.h:290
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:344
Json::Value missing_field_error(std::string const &name)
Definition: ErrorCodes.h:278
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.
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_FIELDS_DEPRECATED
Definition: ErrorCodes.h:172
@ 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:184
constexpr ErrorInfo()
Definition: ErrorCodes.h:186
constexpr ErrorInfo(error_code_i code_, char const *token_, char const *message_)
Definition: ErrorCodes.h:194
Json::StaticString message
Definition: ErrorCodes.h:216
Json::StaticString token
Definition: ErrorCodes.h:215
constexpr ErrorInfo(error_code_i code_, char const *token_, char const *message_, int http_status_)
Definition: ErrorCodes.h:202