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