forked from XRPLF/rippled
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathErrorCodes.h
333 lines (282 loc) · 8.71 KB
/
ErrorCodes.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012 - 2019 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef RIPPLE_PROTOCOL_ERRORCODES_H_INCLUDED
#define RIPPLE_PROTOCOL_ERRORCODES_H_INCLUDED
#include <ripple/json/json_value.h>
#include <ripple/protocol/jss.h>
namespace ripple {
// VFALCO NOTE These are outside the RPC namespace
// NOTE: Although the precise numeric values of these codes were never
// intended to be stable, several API endpoints include the numeric values.
// Some users came to rely on the values, meaning that renumbering would be
// a breaking change for those users.
//
// We therefore treat the range of values as stable although they are not
// and are subject to change.
//
// Please only append to this table. Do not "fill-in" gaps and do not re-use
// or repurpose error code values.
enum error_code_i {
// -1 represents codes not listed in this enumeration
rpcUNKNOWN = -1,
rpcSUCCESS = 0,
rpcBAD_SYNTAX = 1,
rpcJSON_RPC = 2,
rpcFORBIDDEN = 3,
// Misc failure
// unused 4,
// unused 5,
rpcNO_PERMISSION = 6,
rpcNO_EVENTS = 7,
// unused 8,
rpcTOO_BUSY = 9,
rpcSLOW_DOWN = 10,
rpcHIGH_FEE = 11,
rpcNOT_ENABLED = 12,
rpcNOT_READY = 13,
rpcAMENDMENT_BLOCKED = 14,
// Networking
rpcNO_CLOSED = 15,
rpcNO_CURRENT = 16,
rpcNO_NETWORK = 17,
rpcNOT_SYNCED = 18,
// Ledger state
rpcACT_NOT_FOUND = 19,
// unused 20,
rpcLGR_NOT_FOUND = 21,
rpcLGR_NOT_VALIDATED = 22,
rpcMASTER_DISABLED = 23,
// unused 24,
// unused 25,
// unused 26,
// unused 27,
// unused 28,
rpcTXN_NOT_FOUND = 29,
// unused 30,
// Malformed command
rpcINVALID_PARAMS = 31,
rpcUNKNOWN_COMMAND = 32,
rpcNO_PF_REQUEST = 33,
// Bad parameter
// NOT USED DO NOT USE AGAIN rpcACT_BITCOIN = 34,
rpcACT_MALFORMED = 35,
rpcALREADY_MULTISIG = 36,
rpcALREADY_SINGLE_SIG = 37,
// unused 38,
// unused 39,
rpcBAD_FEATURE = 40,
rpcBAD_ISSUER = 41,
rpcBAD_MARKET = 42,
rpcBAD_SECRET = 43,
rpcBAD_SEED = 44,
rpcCHANNEL_MALFORMED = 45,
rpcCHANNEL_AMT_MALFORMED = 46,
rpcCOMMAND_MISSING = 47,
rpcDST_ACT_MALFORMED = 48,
rpcDST_ACT_MISSING = 49,
rpcDST_ACT_NOT_FOUND = 50,
rpcDST_AMT_MALFORMED = 51,
rpcDST_AMT_MISSING = 52,
rpcDST_ISR_MALFORMED = 53,
// unused 54,
// unused 55,
// unused 56,
rpcLGR_IDXS_INVALID = 57,
rpcLGR_IDX_MALFORMED = 58,
// unused 59,
// unused 60,
// unused 61,
rpcPUBLIC_MALFORMED = 62,
rpcSIGNING_MALFORMED = 63,
rpcSENDMAX_MALFORMED = 64,
rpcSRC_ACT_MALFORMED = 65,
rpcSRC_ACT_MISSING = 66,
rpcSRC_ACT_NOT_FOUND = 67,
// unused 68,
rpcSRC_CUR_MALFORMED = 69,
rpcSRC_ISR_MALFORMED = 70,
rpcSTREAM_MALFORMED = 71,
rpcATX_DEPRECATED = 72,
// Internal error (should never happen)
rpcINTERNAL = 73, // Generic internal error.
rpcNOT_IMPL = 74,
rpcNOT_SUPPORTED = 75,
rpcBAD_KEY_TYPE = 76,
rpcDB_DESERIALIZATION = 77,
rpcEXCESSIVE_LGR_RANGE = 78,
rpcINVALID_LGR_RANGE = 79,
rpcLAST =
rpcINVALID_LGR_RANGE // rpcLAST should always equal the last code.=
};
/** Codes returned in the `warnings` array of certain RPC commands.
These values need to remain stable.
*/
enum warning_code_i {
warnRPC_UNSUPPORTED_MAJORITY = 1001,
warnRPC_AMENDMENT_BLOCKED = 1002,
};
//------------------------------------------------------------------------------
// VFALCO NOTE these should probably not be in the RPC namespace.
namespace RPC {
/** Maps an rpc error code to its token and default message. */
struct ErrorInfo
{
// Default ctor needed to produce an empty std::array during constexpr eval.
constexpr ErrorInfo()
: code(rpcUNKNOWN), token("unknown"), message("An unknown error code.")
{
}
constexpr ErrorInfo(
error_code_i code_,
char const* token_,
char const* message_)
: code(code_), token(token_), message(message_)
{
}
error_code_i code;
Json::StaticString token;
Json::StaticString message;
};
/** Returns an ErrorInfo that reflects the error code. */
ErrorInfo const&
get_error_info(error_code_i code);
/** Add or update the json update to reflect the error code. */
/** @{ */
template <class JsonValue>
void
inject_error(error_code_i code, JsonValue& json)
{
ErrorInfo const& info(get_error_info(code));
json[jss::error] = info.token;
json[jss::error_code] = info.code;
json[jss::error_message] = info.message;
}
template <class JsonValue>
void
inject_error(int code, JsonValue& json)
{
inject_error(error_code_i(code), json);
}
template <class JsonValue>
void
inject_error(error_code_i code, std::string const& message, JsonValue& json)
{
ErrorInfo const& info(get_error_info(code));
json[jss::error] = info.token;
json[jss::error_code] = info.code;
json[jss::error_message] = message;
}
/** @} */
/** Returns a new json object that reflects the error code. */
/** @{ */
Json::Value
make_error(error_code_i code);
Json::Value
make_error(error_code_i code, std::string const& message);
/** @} */
/** Returns a new json object that indicates invalid parameters. */
/** @{ */
inline Json::Value
make_param_error(std::string const& message)
{
return make_error(rpcINVALID_PARAMS, message);
}
inline std::string
missing_field_message(std::string const& name)
{
return "Missing field '" + name + "'.";
}
inline Json::Value
missing_field_error(std::string const& name)
{
return make_param_error(missing_field_message(name));
}
inline Json::Value
missing_field_error(Json::StaticString name)
{
return missing_field_error(std::string(name));
}
inline std::string
object_field_message(std::string const& name)
{
return "Invalid field '" + name + "', not object.";
}
inline Json::Value
object_field_error(std::string const& name)
{
return make_param_error(object_field_message(name));
}
inline Json::Value
object_field_error(Json::StaticString name)
{
return object_field_error(std::string(name));
}
inline std::string
invalid_field_message(std::string const& name)
{
return "Invalid field '" + name + "'.";
}
inline std::string
invalid_field_message(Json::StaticString name)
{
return invalid_field_message(std::string(name));
}
inline Json::Value
invalid_field_error(std::string const& name)
{
return make_param_error(invalid_field_message(name));
}
inline Json::Value
invalid_field_error(Json::StaticString name)
{
return invalid_field_error(std::string(name));
}
inline std::string
expected_field_message(std::string const& name, std::string const& type)
{
return "Invalid field '" + name + "', not " + type + ".";
}
inline std::string
expected_field_message(Json::StaticString name, std::string const& type)
{
return expected_field_message(std::string(name), type);
}
inline Json::Value
expected_field_error(std::string const& name, std::string const& type)
{
return make_param_error(expected_field_message(name, type));
}
inline Json::Value
expected_field_error(Json::StaticString name, std::string const& type)
{
return expected_field_error(std::string(name), type);
}
inline Json::Value
not_validator_error()
{
return make_param_error("not a validator");
}
/** @} */
/** Returns `true` if the json contains an rpc error specification. */
bool
contains_error(Json::Value const& json);
} // namespace RPC
/** Returns a single string with the contents of an RPC error. */
std::string
rpcErrorString(Json::Value const& jv);
} // namespace ripple
#endif