xrpld
Loading...
Searching...
No Matches
ErrorCodes.h
1#pragma once
2
3#include <xrpl/json/json_value.h>
4
5#include <string>
6
7namespace 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)
24 // -1 represents codes not listed in this enumeration
26
28
32
34 // Misc failure
35 // unused 5,
38 // unused 8,
45
46 // Networking
51
52 // Ledger state
54 // unused 20,
58 // unused 24,
59 // unused 25,
60 // unused 26,
61 // unused 27,
62 // unused 28,
65
66 // Malformed command
70
71 // Bad parameter
72 // NOT USED DO NOT USE AGAIN rpcACT_BITCOIN = 34,
76 // unused 38,
77 // unused 39,
92 // unused 54,
93 // unused 55,
94 // unused 56,
97 // unused 59,
98 // unused 60,
99 // unused 61,
111
112 // Internal error (should never happen)
113 RpcInternal = 73, // Generic internal error.
121
122 // unused = 90,
123 // DEPRECATED. New code must not use this value.
125
127
128 // AMM
130
131 // Oracle
133
134 // deposit_authorized + credentials
136
137 // Simulate
139
140 // Pathfinding
142
143 // ledger_entry
146
147 RpcLast = RpcUnexpectedLedgerType // rpcLAST should always equal the last code.
148};
149
155// Protocol-wide, 50+ files
156// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
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
170namespace rpc {
171
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)
185 {
186 }
187
188 constexpr ErrorInfo(ErrorCodeI code, char const* token, char const* message, int httpStatus)
190 {
191 }
192
197};
198
202ErrorInfo const&
204
209void
211
212void
213injectError(ErrorCodeI code, std::string const& message, json::Value& json);
215
223makeError(ErrorCodeI code, std::string const& message);
225
230inline json::Value
232{
233 return makeError(RpcInvalidParams, message);
234}
235
236inline std::string
238{
239 return "Missing field '" + name + "'.";
240}
241
242inline json::Value
244{
246}
247
248inline json::Value
253
254inline std::string
256{
257 return "Invalid field '" + name + "', not object.";
258}
259
260inline json::Value
262{
264}
265
266inline json::Value
271
272inline std::string
274{
275 return "Invalid field '" + name + "'.";
276}
277
278inline std::string
283
284inline json::Value
286{
288}
289
290inline json::Value
295
296inline std::string
298{
299 return "Invalid field '" + name + "', not " + type + ".";
300}
301
302inline std::string
304{
305 return expectedFieldMessage(std::string(name), type);
306}
307
308inline json::Value
310{
311 return makeParamError(expectedFieldMessage(name, type));
312}
313
314inline json::Value
316{
317 return expectedFieldError(std::string(name), type);
318}
319
320inline json::Value
322{
323 return makeParamError("not a validator");
324}
325
327
331bool
333
337int
339
340} // namespace rpc
341
346rpcErrorString(json::Value const& jv);
347
348} // namespace xrpl
Lightweight wrapper to tag static string.
Definition json_value.h:48
Represents a JSON value.
Definition json_value.h:117
JSON (JavaScript Object Notation).
Definition json_errors.h:5
std::string objectFieldMessage(std::string const &name)
Definition ErrorCodes.h:255
json::Value notValidatorError()
Definition ErrorCodes.h:321
json::Value expectedFieldError(std::string const &name, std::string const &type)
Definition ErrorCodes.h:309
bool containsError(json::Value const &json)
Returns true if the json contains an rpc error specification.
std::string invalidFieldMessage(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:231
void injectError(ErrorCodeI code, json::Value &json)
Add or update the json update to reflect the error code.
json::Value invalidFieldError(std::string const &name)
Definition ErrorCodes.h:285
int errorCodeHttpStatus(ErrorCodeI code)
Returns http status that corresponds to the error code.
std::string expectedFieldMessage(std::string const &name, std::string const &type)
Definition ErrorCodes.h:297
std::string missingFieldMessage(std::string const &name)
Definition ErrorCodes.h:237
json::Value missingFieldError(std::string const &name)
Definition ErrorCodes.h:243
json::Value makeError(ErrorCodeI code)
Returns a new json object that reflects the error code.
ErrorInfo const & getErrorInfo(ErrorCodeI code)
Returns an ErrorInfo that reflects the error code.
json::Value objectFieldError(std::string const &name)
Definition ErrorCodes.h:261
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:157
@ WarnRpcAmendmentBlocked
Definition ErrorCodes.h:159
@ WarnRpcFieldsDeprecated
Definition ErrorCodes.h:162
@ WarnRpcUnsupportedMajority
Definition ErrorCodes.h:158
@ WarnRpcExpiredValidatorList
Definition ErrorCodes.h:160
ErrorCodeI
Definition ErrorCodes.h:23
@ RpcDstAmtMalformed
Definition ErrorCodes.h:89
@ RpcDstActNotFound
Definition ErrorCodes.h:88
@ RpcBadSecret
Definition ErrorCodes.h:81
@ RpcBadCredentials
Definition ErrorCodes.h:135
@ RpcChannelAmtMalformed
Definition ErrorCodes.h:84
@ RpcNoClosed
Definition ErrorCodes.h:47
@ RpcInvalidHotwallet
Definition ErrorCodes.h:64
@ RpcBadFeature
Definition ErrorCodes.h:78
@ RpcOracleMalformed
Definition ErrorCodes.h:132
@ RpcInternal
Definition ErrorCodes.h:113
@ RpcBadIssuer
Definition ErrorCodes.h:79
@ RpcStreamMalformed
Definition ErrorCodes.h:109
@ RpcDelegateActNotFound
Definition ErrorCodes.h:106
@ RpcLast
Definition ErrorCodes.h:147
@ RpcSrcActMalformed
Definition ErrorCodes.h:103
@ RpcNotImpl
Definition ErrorCodes.h:114
@ RpcNotSupported
Definition ErrorCodes.h:115
@ RpcAlreadySingleSig
Definition ErrorCodes.h:75
@ RpcNoNetwork
Definition ErrorCodes.h:49
@ RpcSigningMalformed
Definition ErrorCodes.h:101
@ RpcLgrNotFound
Definition ErrorCodes.h:55
@ RpcObjectNotFound
Definition ErrorCodes.h:126
@ RpcNoPfRequest
Definition ErrorCodes.h:69
@ RpcActNotFound
Definition ErrorCodes.h:53
@ RpcBadMarket
Definition ErrorCodes.h:80
@ RpcEntryNotFound
Definition ErrorCodes.h:144
@ RpcAmendmentBlocked
Definition ErrorCodes.h:44
@ RpcBadKeyType
Definition ErrorCodes.h:116
@ RpcSuccess
Definition ErrorCodes.h:27
@ RpcUnknown
Definition ErrorCodes.h:25
@ RpcExpiredValidatorList
Definition ErrorCodes.h:120
@ RpcActMalformed
Definition ErrorCodes.h:73
@ RpcNotSynced
Definition ErrorCodes.h:50
@ RpcHighFee
Definition ErrorCodes.h:41
@ RpcExcessiveLgrRange
Definition ErrorCodes.h:118
@ RpcMasterDisabled
Definition ErrorCodes.h:57
@ RpcDstActMalformed
Definition ErrorCodes.h:86
@ RpcTxnNotFound
Definition ErrorCodes.h:63
@ RpcNotReady
Definition ErrorCodes.h:43
@ RpcLgrIdxsInvalid
Definition ErrorCodes.h:95
@ RpcDomainMalformed
Definition ErrorCodes.h:141
@ RpcPublicMalformed
Definition ErrorCodes.h:100
@ RpcCommandMissing
Definition ErrorCodes.h:85
@ RpcSlowDown
Definition ErrorCodes.h:40
@ RpcJsonRpc
Definition ErrorCodes.h:30
@ RpcAtxDeprecated
Definition ErrorCodes.h:110
@ RpcSrcActMissing
Definition ErrorCodes.h:104
@ RpcDstActMissing
Definition ErrorCodes.h:87
@ RpcSrcCurMalformed
Definition ErrorCodes.h:107
@ RpcNoEvents
Definition ErrorCodes.h:37
@ RpcUnexpectedLedgerType
Definition ErrorCodes.h:145
@ RpcDstAmtMissing
Definition ErrorCodes.h:90
@ RpcIssueMalformed
Definition ErrorCodes.h:129
@ RpcReportingUnsupported
Definition ErrorCodes.h:124
@ RpcNotEnabled
Definition ErrorCodes.h:42
@ RpcInvalidParams
Definition ErrorCodes.h:67
@ RpcLgrNotValidated
Definition ErrorCodes.h:56
@ RpcSendmaxMalformed
Definition ErrorCodes.h:102
@ RpcBadSeed
Definition ErrorCodes.h:82
@ RpcSrcIsrMalformed
Definition ErrorCodes.h:108
@ RpcBadSyntax
Definition ErrorCodes.h:29
@ RpcWrongNetwork
Definition ErrorCodes.h:33
@ RpcTooBusy
Definition ErrorCodes.h:39
@ RpcDbDeserialization
Definition ErrorCodes.h:117
@ RpcChannelMalformed
Definition ErrorCodes.h:83
@ RpcDstIsrMalformed
Definition ErrorCodes.h:91
@ RpcNoPermission
Definition ErrorCodes.h:36
@ RpcForbidden
Definition ErrorCodes.h:31
@ RpcInvalidLgrRange
Definition ErrorCodes.h:119
@ RpcLgrIdxMalformed
Definition ErrorCodes.h:96
@ RpcUnknownCommand
Definition ErrorCodes.h:68
@ RpcTxSigned
Definition ErrorCodes.h:138
@ RpcAlreadyMultisig
Definition ErrorCodes.h:74
@ RpcNoCurrent
Definition ErrorCodes.h:48
@ RpcSrcActNotFound
Definition ErrorCodes.h:105
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:176
constexpr ErrorInfo()
Definition ErrorCodes.h:178
json::StaticString message
Definition ErrorCodes.h:195
constexpr ErrorInfo(ErrorCodeI code, char const *token, char const *message, int httpStatus)
Definition ErrorCodes.h:188
constexpr ErrorInfo(ErrorCodeI code, char const *token, char const *message)
Definition ErrorCodes.h:183
json::StaticString token
Definition ErrorCodes.h:194