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