xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
include
xrpl
protocol
ErrorCodes.h
1
#pragma once
2
3
#include <xrpl/json/json_value.h>
4
5
#include <
string
>
6
7
namespace
xrpl
{
8
9
// VFALCO NOTE These are outside the RPC namespace
10
11
// NOTE: Although the precise numeric values of these codes were never
12
// intended to be stable, several API endpoints include the numeric values.
13
// Some users came to rely on the values, meaning that renumbering would be
14
// a breaking change for those users.
15
//
16
// We therefore treat the range of values as stable although they are not
17
// and are subject to change.
18
//
19
// Please only append to this table. Do not "fill-in" gaps and do not re-use
20
// or repurpose error code values.
21
// Protocol-wide, 50+ files
22
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
23
enum
ErrorCodeI
{
24
// -1 represents codes not listed in this enumeration
25
RpcUnknown
= -1,
26
27
RpcSuccess
= 0,
28
29
RpcBadSyntax
= 1,
30
RpcJsonRpc
= 2,
31
RpcForbidden
= 3,
32
33
RpcWrongNetwork
= 4,
34
// Misc failure
35
// unused 5,
36
RpcNoPermission
= 6,
37
RpcNoEvents
= 7,
38
// unused 8,
39
RpcTooBusy
= 9,
40
RpcSlowDown
= 10,
41
RpcHighFee
= 11,
42
RpcNotEnabled
= 12,
43
RpcNotReady
= 13,
44
RpcAmendmentBlocked
= 14,
45
46
// Networking
47
RpcNoClosed
= 15,
48
RpcNoCurrent
= 16,
49
RpcNoNetwork
= 17,
50
RpcNotSynced
= 18,
51
52
// Ledger state
53
RpcActNotFound
= 19,
54
// unused 20,
55
RpcLgrNotFound
= 21,
56
RpcLgrNotValidated
= 22,
57
RpcMasterDisabled
= 23,
58
// unused 24,
59
// unused 25,
60
// unused 26,
61
// unused 27,
62
// unused 28,
63
RpcTxnNotFound
= 29,
64
RpcInvalidHotwallet
= 30,
65
66
// Malformed command
67
RpcInvalidParams
= 31,
68
RpcUnknownCommand
= 32,
69
RpcNoPfRequest
= 33,
70
71
// Bad parameter
72
// NOT USED DO NOT USE AGAIN rpcACT_BITCOIN = 34,
73
RpcActMalformed
= 35,
74
RpcAlreadyMultisig
= 36,
75
RpcAlreadySingleSig
= 37,
76
// unused 38,
77
// unused 39,
78
RpcBadFeature
= 40,
79
RpcBadIssuer
= 41,
80
RpcBadMarket
= 42,
81
RpcBadSecret
= 43,
82
RpcBadSeed
= 44,
83
RpcChannelMalformed
= 45,
84
RpcChannelAmtMalformed
= 46,
85
RpcCommandMissing
= 47,
86
RpcDstActMalformed
= 48,
87
RpcDstActMissing
= 49,
88
RpcDstActNotFound
= 50,
89
RpcDstAmtMalformed
= 51,
90
RpcDstAmtMissing
= 52,
91
RpcDstIsrMalformed
= 53,
92
// unused 54,
93
// unused 55,
94
// unused 56,
95
RpcLgrIdxsInvalid
= 57,
96
RpcLgrIdxMalformed
= 58,
97
// unused 59,
98
// unused 60,
99
// unused 61,
100
RpcPublicMalformed
= 62,
101
RpcSigningMalformed
= 63,
102
RpcSendmaxMalformed
= 64,
103
RpcSrcActMalformed
= 65,
104
RpcSrcActMissing
= 66,
105
RpcSrcActNotFound
= 67,
106
RpcDelegateActNotFound
= 68,
107
RpcSrcCurMalformed
= 69,
108
RpcSrcIsrMalformed
= 70,
109
RpcStreamMalformed
= 71,
110
RpcAtxDeprecated
= 72,
111
112
// Internal error (should never happen)
113
RpcInternal
= 73,
// Generic internal error.
114
RpcNotImpl
= 74,
115
RpcNotSupported
= 75,
116
RpcBadKeyType
= 76,
117
RpcDbDeserialization
= 77,
118
RpcExcessiveLgrRange
= 78,
119
RpcInvalidLgrRange
= 79,
120
RpcExpiredValidatorList
= 80,
121
122
// unused = 90,
123
// DEPRECATED. New code must not use this value.
124
RpcReportingUnsupported
= 91,
125
126
RpcObjectNotFound
= 92,
127
128
// AMM
129
RpcIssueMalformed
= 93,
130
131
// Oracle
132
RpcOracleMalformed
= 94,
133
134
// deposit_authorized + credentials
135
RpcBadCredentials
= 95,
136
137
// Simulate
138
RpcTxSigned
= 96,
139
140
// Pathfinding
141
RpcDomainMalformed
= 97,
142
143
// ledger_entry
144
RpcEntryNotFound
= 98,
145
RpcUnexpectedLedgerType
= 99,
146
147
RpcLast
=
RpcUnexpectedLedgerType
// rpcLAST should always equal the last code.
148
};
149
155
// Protocol-wide, 50+ files
156
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
157
enum
WarningCodeI
{
158
WarnRpcUnsupportedMajority
= 1001,
159
WarnRpcAmendmentBlocked
= 1002,
160
WarnRpcExpiredValidatorList
= 1003,
161
// unused = 1004
162
WarnRpcFieldsDeprecated
= 2004,
// xrpld needs to maintain
163
// compatibility with Clio on this code.
164
};
165
166
//------------------------------------------------------------------------------
167
168
// VFALCO NOTE these should probably not be in the RPC namespace.
169
170
namespace
rpc {
171
175
struct
ErrorInfo
176
{
177
// Default ctor needed to produce an empty std::array during constexpr eval.
178
constexpr
ErrorInfo
()
179
:
code
(
RpcUnknown
),
token
(
"unknown"
),
message
(
"An unknown error code."
),
httpStatus
(200)
180
{
181
}
182
183
constexpr
ErrorInfo
(
ErrorCodeI
code
,
char
const
*
token
,
char
const
*
message
)
184
:
code
(
code
),
token
(
token
),
message
(
message
),
httpStatus
(200)
185
{
186
}
187
188
constexpr
ErrorInfo
(
ErrorCodeI
code
,
char
const
*
token
,
char
const
*
message
,
int
httpStatus
)
189
:
code
(
code
),
token
(
token
),
message
(
message
),
httpStatus
(
httpStatus
)
190
{
191
}
192
193
ErrorCodeI
code
;
194
json::StaticString
token
;
195
json::StaticString
message
;
196
int
httpStatus
;
197
};
198
202
ErrorInfo
const
&
203
getErrorInfo
(
ErrorCodeI
code);
204
209
void
210
injectError
(
ErrorCodeI
code,
json::Value
&
json
);
211
212
void
213
injectError
(
ErrorCodeI
code,
std::string
const
& message,
json::Value
&
json
);
215
220
json::Value
221
makeError
(
ErrorCodeI
code);
222
json::Value
223
makeError
(
ErrorCodeI
code,
std::string
const
& message);
225
230
inline
json::Value
231
makeParamError
(
std::string
const
& message)
232
{
233
return
makeError
(
RpcInvalidParams
, message);
234
}
235
236
inline
std::string
237
missingFieldMessage
(
std::string
const
& name)
238
{
239
return
"Missing field '"
+ name +
"'."
;
240
}
241
242
inline
json::Value
243
missingFieldError
(
std::string
const
& name)
244
{
245
return
makeParamError
(
missingFieldMessage
(name));
246
}
247
248
inline
json::Value
249
missingFieldError
(
json::StaticString
name)
250
{
251
return
missingFieldError
(
std::string
(name));
252
}
253
254
inline
std::string
255
objectFieldMessage
(
std::string
const
& name)
256
{
257
return
"Invalid field '"
+ name +
"', not object."
;
258
}
259
260
inline
json::Value
261
objectFieldError
(
std::string
const
& name)
262
{
263
return
makeParamError
(
objectFieldMessage
(name));
264
}
265
266
inline
json::Value
267
objectFieldError
(
json::StaticString
name)
268
{
269
return
objectFieldError
(
std::string
(name));
270
}
271
272
inline
std::string
273
invalidFieldMessage
(
std::string
const
& name)
274
{
275
return
"Invalid field '"
+ name +
"'."
;
276
}
277
278
inline
std::string
279
invalidFieldMessage
(
json::StaticString
name)
280
{
281
return
invalidFieldMessage
(
std::string
(name));
282
}
283
284
inline
json::Value
285
invalidFieldError
(
std::string
const
& name)
286
{
287
return
makeParamError
(
invalidFieldMessage
(name));
288
}
289
290
inline
json::Value
291
invalidFieldError
(
json::StaticString
name)
292
{
293
return
invalidFieldError
(
std::string
(name));
294
}
295
296
inline
std::string
297
expectedFieldMessage
(
std::string
const
& name,
std::string
const
& type)
298
{
299
return
"Invalid field '"
+ name +
"', not "
+ type +
"."
;
300
}
301
302
inline
std::string
303
expectedFieldMessage
(
json::StaticString
name,
std::string
const
& type)
304
{
305
return
expectedFieldMessage
(
std::string
(name), type);
306
}
307
308
inline
json::Value
309
expectedFieldError
(
std::string
const
& name,
std::string
const
& type)
310
{
311
return
makeParamError
(
expectedFieldMessage
(name, type));
312
}
313
314
inline
json::Value
315
expectedFieldError
(
json::StaticString
name,
std::string
const
& type)
316
{
317
return
expectedFieldError
(
std::string
(name), type);
318
}
319
320
inline
json::Value
321
notValidatorError
()
322
{
323
return
makeParamError
(
"not a validator"
);
324
}
325
327
331
bool
332
containsError
(
json::Value
const
&
json
);
333
337
int
338
errorCodeHttpStatus
(
ErrorCodeI
code);
339
340
}
// namespace rpc
341
345
std::string
346
rpcErrorString
(
json::Value
const
& jv);
347
348
}
// namespace xrpl
std::string
json::StaticString
Lightweight wrapper to tag static string.
Definition
json_value.h:48
json::Value
Represents a JSON value.
Definition
json_value.h:117
json
JSON (JavaScript Object Notation).
Definition
json_errors.h:5
xrpl::rpc::objectFieldMessage
std::string objectFieldMessage(std::string const &name)
Definition
ErrorCodes.h:255
xrpl::rpc::notValidatorError
json::Value notValidatorError()
Definition
ErrorCodes.h:321
xrpl::rpc::expectedFieldError
json::Value expectedFieldError(std::string const &name, std::string const &type)
Definition
ErrorCodes.h:309
xrpl::rpc::containsError
bool containsError(json::Value const &json)
Returns true if the json contains an rpc error specification.
Definition
ErrorCodes.cpp:206
xrpl::rpc::invalidFieldMessage
std::string invalidFieldMessage(std::string const &name)
Definition
ErrorCodes.h:273
xrpl::rpc::makeParamError
json::Value makeParamError(std::string const &message)
Returns a new json object that indicates invalid parameters.
Definition
ErrorCodes.h:231
xrpl::rpc::injectError
void injectError(ErrorCodeI code, json::Value &json)
Add or update the json update to reflect the error code.
Definition
ErrorCodes.cpp:164
xrpl::rpc::invalidFieldError
json::Value invalidFieldError(std::string const &name)
Definition
ErrorCodes.h:285
xrpl::rpc::errorCodeHttpStatus
int errorCodeHttpStatus(ErrorCodeI code)
Returns http status that corresponds to the error code.
Definition
ErrorCodes.cpp:212
xrpl::rpc::expectedFieldMessage
std::string expectedFieldMessage(std::string const &name, std::string const &type)
Definition
ErrorCodes.h:297
xrpl::rpc::missingFieldMessage
std::string missingFieldMessage(std::string const &name)
Definition
ErrorCodes.h:237
xrpl::rpc::missingFieldError
json::Value missingFieldError(std::string const &name)
Definition
ErrorCodes.h:243
xrpl::rpc::makeError
json::Value makeError(ErrorCodeI code)
Returns a new json object that reflects the error code.
Definition
ErrorCodes.cpp:190
xrpl::rpc::getErrorInfo
ErrorInfo const & getErrorInfo(ErrorCodeI code)
Returns an ErrorInfo that reflects the error code.
Definition
ErrorCodes.cpp:182
xrpl::rpc::objectFieldError
json::Value objectFieldError(std::string const &name)
Definition
ErrorCodes.h:261
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::WarningCodeI
WarningCodeI
Codes returned in the warnings array of certain RPC commands.
Definition
ErrorCodes.h:157
xrpl::WarnRpcAmendmentBlocked
@ WarnRpcAmendmentBlocked
Definition
ErrorCodes.h:159
xrpl::WarnRpcFieldsDeprecated
@ WarnRpcFieldsDeprecated
Definition
ErrorCodes.h:162
xrpl::WarnRpcUnsupportedMajority
@ WarnRpcUnsupportedMajority
Definition
ErrorCodes.h:158
xrpl::WarnRpcExpiredValidatorList
@ WarnRpcExpiredValidatorList
Definition
ErrorCodes.h:160
xrpl::ErrorCodeI
ErrorCodeI
Definition
ErrorCodes.h:23
xrpl::RpcDstAmtMalformed
@ RpcDstAmtMalformed
Definition
ErrorCodes.h:89
xrpl::RpcDstActNotFound
@ RpcDstActNotFound
Definition
ErrorCodes.h:88
xrpl::RpcBadSecret
@ RpcBadSecret
Definition
ErrorCodes.h:81
xrpl::RpcBadCredentials
@ RpcBadCredentials
Definition
ErrorCodes.h:135
xrpl::RpcChannelAmtMalformed
@ RpcChannelAmtMalformed
Definition
ErrorCodes.h:84
xrpl::RpcNoClosed
@ RpcNoClosed
Definition
ErrorCodes.h:47
xrpl::RpcInvalidHotwallet
@ RpcInvalidHotwallet
Definition
ErrorCodes.h:64
xrpl::RpcBadFeature
@ RpcBadFeature
Definition
ErrorCodes.h:78
xrpl::RpcOracleMalformed
@ RpcOracleMalformed
Definition
ErrorCodes.h:132
xrpl::RpcInternal
@ RpcInternal
Definition
ErrorCodes.h:113
xrpl::RpcBadIssuer
@ RpcBadIssuer
Definition
ErrorCodes.h:79
xrpl::RpcStreamMalformed
@ RpcStreamMalformed
Definition
ErrorCodes.h:109
xrpl::RpcDelegateActNotFound
@ RpcDelegateActNotFound
Definition
ErrorCodes.h:106
xrpl::RpcLast
@ RpcLast
Definition
ErrorCodes.h:147
xrpl::RpcSrcActMalformed
@ RpcSrcActMalformed
Definition
ErrorCodes.h:103
xrpl::RpcNotImpl
@ RpcNotImpl
Definition
ErrorCodes.h:114
xrpl::RpcNotSupported
@ RpcNotSupported
Definition
ErrorCodes.h:115
xrpl::RpcAlreadySingleSig
@ RpcAlreadySingleSig
Definition
ErrorCodes.h:75
xrpl::RpcNoNetwork
@ RpcNoNetwork
Definition
ErrorCodes.h:49
xrpl::RpcSigningMalformed
@ RpcSigningMalformed
Definition
ErrorCodes.h:101
xrpl::RpcLgrNotFound
@ RpcLgrNotFound
Definition
ErrorCodes.h:55
xrpl::RpcObjectNotFound
@ RpcObjectNotFound
Definition
ErrorCodes.h:126
xrpl::RpcNoPfRequest
@ RpcNoPfRequest
Definition
ErrorCodes.h:69
xrpl::RpcActNotFound
@ RpcActNotFound
Definition
ErrorCodes.h:53
xrpl::RpcBadMarket
@ RpcBadMarket
Definition
ErrorCodes.h:80
xrpl::RpcEntryNotFound
@ RpcEntryNotFound
Definition
ErrorCodes.h:144
xrpl::RpcAmendmentBlocked
@ RpcAmendmentBlocked
Definition
ErrorCodes.h:44
xrpl::RpcBadKeyType
@ RpcBadKeyType
Definition
ErrorCodes.h:116
xrpl::RpcSuccess
@ RpcSuccess
Definition
ErrorCodes.h:27
xrpl::RpcUnknown
@ RpcUnknown
Definition
ErrorCodes.h:25
xrpl::RpcExpiredValidatorList
@ RpcExpiredValidatorList
Definition
ErrorCodes.h:120
xrpl::RpcActMalformed
@ RpcActMalformed
Definition
ErrorCodes.h:73
xrpl::RpcNotSynced
@ RpcNotSynced
Definition
ErrorCodes.h:50
xrpl::RpcHighFee
@ RpcHighFee
Definition
ErrorCodes.h:41
xrpl::RpcExcessiveLgrRange
@ RpcExcessiveLgrRange
Definition
ErrorCodes.h:118
xrpl::RpcMasterDisabled
@ RpcMasterDisabled
Definition
ErrorCodes.h:57
xrpl::RpcDstActMalformed
@ RpcDstActMalformed
Definition
ErrorCodes.h:86
xrpl::RpcTxnNotFound
@ RpcTxnNotFound
Definition
ErrorCodes.h:63
xrpl::RpcNotReady
@ RpcNotReady
Definition
ErrorCodes.h:43
xrpl::RpcLgrIdxsInvalid
@ RpcLgrIdxsInvalid
Definition
ErrorCodes.h:95
xrpl::RpcDomainMalformed
@ RpcDomainMalformed
Definition
ErrorCodes.h:141
xrpl::RpcPublicMalformed
@ RpcPublicMalformed
Definition
ErrorCodes.h:100
xrpl::RpcCommandMissing
@ RpcCommandMissing
Definition
ErrorCodes.h:85
xrpl::RpcSlowDown
@ RpcSlowDown
Definition
ErrorCodes.h:40
xrpl::RpcJsonRpc
@ RpcJsonRpc
Definition
ErrorCodes.h:30
xrpl::RpcAtxDeprecated
@ RpcAtxDeprecated
Definition
ErrorCodes.h:110
xrpl::RpcSrcActMissing
@ RpcSrcActMissing
Definition
ErrorCodes.h:104
xrpl::RpcDstActMissing
@ RpcDstActMissing
Definition
ErrorCodes.h:87
xrpl::RpcSrcCurMalformed
@ RpcSrcCurMalformed
Definition
ErrorCodes.h:107
xrpl::RpcNoEvents
@ RpcNoEvents
Definition
ErrorCodes.h:37
xrpl::RpcUnexpectedLedgerType
@ RpcUnexpectedLedgerType
Definition
ErrorCodes.h:145
xrpl::RpcDstAmtMissing
@ RpcDstAmtMissing
Definition
ErrorCodes.h:90
xrpl::RpcIssueMalformed
@ RpcIssueMalformed
Definition
ErrorCodes.h:129
xrpl::RpcReportingUnsupported
@ RpcReportingUnsupported
Definition
ErrorCodes.h:124
xrpl::RpcNotEnabled
@ RpcNotEnabled
Definition
ErrorCodes.h:42
xrpl::RpcInvalidParams
@ RpcInvalidParams
Definition
ErrorCodes.h:67
xrpl::RpcLgrNotValidated
@ RpcLgrNotValidated
Definition
ErrorCodes.h:56
xrpl::RpcSendmaxMalformed
@ RpcSendmaxMalformed
Definition
ErrorCodes.h:102
xrpl::RpcBadSeed
@ RpcBadSeed
Definition
ErrorCodes.h:82
xrpl::RpcSrcIsrMalformed
@ RpcSrcIsrMalformed
Definition
ErrorCodes.h:108
xrpl::RpcBadSyntax
@ RpcBadSyntax
Definition
ErrorCodes.h:29
xrpl::RpcWrongNetwork
@ RpcWrongNetwork
Definition
ErrorCodes.h:33
xrpl::RpcTooBusy
@ RpcTooBusy
Definition
ErrorCodes.h:39
xrpl::RpcDbDeserialization
@ RpcDbDeserialization
Definition
ErrorCodes.h:117
xrpl::RpcChannelMalformed
@ RpcChannelMalformed
Definition
ErrorCodes.h:83
xrpl::RpcDstIsrMalformed
@ RpcDstIsrMalformed
Definition
ErrorCodes.h:91
xrpl::RpcNoPermission
@ RpcNoPermission
Definition
ErrorCodes.h:36
xrpl::RpcForbidden
@ RpcForbidden
Definition
ErrorCodes.h:31
xrpl::RpcInvalidLgrRange
@ RpcInvalidLgrRange
Definition
ErrorCodes.h:119
xrpl::RpcLgrIdxMalformed
@ RpcLgrIdxMalformed
Definition
ErrorCodes.h:96
xrpl::RpcUnknownCommand
@ RpcUnknownCommand
Definition
ErrorCodes.h:68
xrpl::RpcTxSigned
@ RpcTxSigned
Definition
ErrorCodes.h:138
xrpl::RpcAlreadyMultisig
@ RpcAlreadyMultisig
Definition
ErrorCodes.h:74
xrpl::RpcNoCurrent
@ RpcNoCurrent
Definition
ErrorCodes.h:48
xrpl::RpcSrcActNotFound
@ RpcSrcActNotFound
Definition
ErrorCodes.h:105
xrpl::rpcErrorString
std::string rpcErrorString(json::Value const &jv)
Returns a single string with the contents of an RPC error.
Definition
ErrorCodes.cpp:220
string
xrpl::rpc::ErrorInfo
Maps an rpc error code to its token, default message, and HTTP status.
Definition
ErrorCodes.h:176
xrpl::rpc::ErrorInfo::ErrorInfo
constexpr ErrorInfo()
Definition
ErrorCodes.h:178
xrpl::rpc::ErrorInfo::message
json::StaticString message
Definition
ErrorCodes.h:195
xrpl::rpc::ErrorInfo::httpStatus
int httpStatus
Definition
ErrorCodes.h:196
xrpl::rpc::ErrorInfo::ErrorInfo
constexpr ErrorInfo(ErrorCodeI code, char const *token, char const *message, int httpStatus)
Definition
ErrorCodes.h:188
xrpl::rpc::ErrorInfo::ErrorInfo
constexpr ErrorInfo(ErrorCodeI code, char const *token, char const *message)
Definition
ErrorCodes.h:183
xrpl::rpc::ErrorInfo::code
ErrorCodeI code
Definition
ErrorCodes.h:193
xrpl::rpc::ErrorInfo::token
json::StaticString token
Definition
ErrorCodes.h:194
Generated by
1.17.0