cfx_rpc_utils/error/error_codes.rs
1#![allow(dead_code)]
2// Copyright 2015-2019 Parity Technologies (UK) Ltd.
3// This file is part of Parity Ethereum.
4
5// Parity Ethereum is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9
10// Parity Ethereum is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14
15// You should have received a copy of the GNU General Public License
16// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
17
18//! RPC Error codes and error objects
19
20/// JsonRPC spec reserved from and including -32768 to -32000 for
21/// pre-defined errors. The reminder of the space is available for
22/// application defined errors.
23///
24/// -32000 to -32099 is defined for "(JsonRPC) Server Error".
25///
26/// We use the same error code number as in Parity Ethereum wherever
27/// possible. Since the error code is almost used up by Parity, we
28/// further reserve [-31999, -31000] for Conflux's extra server error
29/// codes, in the range of "application defined errors" as defined by
30/// JsonRPC.
31
32/// When the number on the right is -32100, check the next variable below.
33///
34/// Please use the number on the right for new error code, then decrease it
35/// by 1.
36///
37/// Do not recycle deprecated error codes.
38const NEXT_SERVER_ERROR_CODE: i64 = -32078;
39/// When the above number is equal to -32100, take the number below on the
40/// right for new error code, then increase it by 1.
41const CFX_EXTRA_SERVER_ERROR_CODE: i64 = -31999;
42
43/// We reserve [-30999, 30000] for application error code. i.e. Error code
44/// which is defined specifically for a particular rpc.
45const CFX_EXTRA_APP_ERROR_CODE: i64 = -30999;
46
47/* Rpc functional related error codes. */
48/// The request is not supported (yet) at this version.
49pub const UNSUPPORTED: i64 = -32000;
50/// The requested feature is deprecated.
51pub const DEPRECATED: i64 = -32070;
52/// The requested feature is experimental.
53pub const EXPERIMENTAL: i64 = -32071;
54/// The node is not able to serve the request due to configuration. e.g. Not
55/// mining, light node, not archive node.
56pub const INCAPABLE: i64 = -32073;
57
58/* Rpc usage related error codes */
59/// When there are too many rpc requests. We limit the number of allowed rpc
60/// requests for attack prevention.
61pub const REQUEST_REJECTED_TOO_MANY_REQUESTS: i64 = -32072;
62/// When the request is considered too much for the rpc function.
63/// The consideration is set individually per rpc. It can be data too large,
64/// or it can be that some performance/security related parameter is outside
65/// the accepted range.
66///
67/// This is mostly an application error but it's generic enough to define it
68/// here.
69pub const REQUEST_REJECTED_LIMIT_DATA: i64 = -32041;
70
71/* Conflux node status related error codes
72 *
73 * When the node is not well-connected to the Conflux network, or when an
74 * ongoing attack is detected, the rpc server should stop providing
75 * on-chain information, and instead return a relevant error code.
76 */
77/// No connection to trusted peers.
78pub const NO_TRUSTED_PEERS: i64 = -32074;
79/// No peers are currently connected or there is insufficient amount of
80/// peers connected.
81pub const NO_PEERS: i64 = -32066;
82pub const CONFLUX_PIVOT_CHAIN_UNSTABLE: i64 = -32075;
83/// The node see a suspicious total mining power or block rate.
84/// It's likely that the node is under attack or the whole Conflux network
85/// enters an abnormal state.
86pub const SUSPICIOUS_MINING_RATE: i64 = -32076;
87/// When the node is still in catch up mode, it is not capable to handle
88/// certain requests. We will return this code in this situation.
89pub const REQUEST_REJECTED_IN_CATCH_UP: i64 = -32077;
90
91/* Other server error codes */
92/// Any exception happened while processing the transaction. Mostly likely
93/// there is an internal error within the server state.
94///
95/// When the server can detect an error with the request itself, it should
96/// return another error code such as invalid params, or for example
97/// CALL_EXECUTION_ERROR.
98pub const EXCEPTION_ERROR: i64 = -32016;
99/// The error can be given to a request about a previous related request
100/// which we can not associate with.
101///
102/// In Parity it was used for rpc check_request(). In parity's comment:
103/// "Checks the progress of a previously posted request (transaction/sign).
104/// Should be given a valid send_transaction ID."
105pub const PREVIOUS_REQUEST_NOT_FOUND: i64 = -32042;
106
107// FIXME: Used in Parity for all Transaction related errors.
108// FIXME: We may process it as general invalid_params with error message?
109// FIXME: How do rpc clients handle errors from send_raw_transaction?
110
111/* Wallet/secret-store/signing related. */
112// FIXME: why didn't we use this error code?
113#[cfg(any(test, feature = "accounts"))]
114pub const ACCOUNT_LOCKED: i64 = -32020;
115// FIXME: why didn't we use this error code?
116#[cfg(any(test, feature = "accounts"))]
117pub const PASSWORD_INVALID: i64 = -32021;
118// FIXME: why didn't we use this error code?
119pub const ACCOUNT_ERROR: i64 = -32023;
120/// Encoding error happened in signing structured data. Related to EIP712.
121pub const ENCODING_ERROR: i64 = -32058;
122
123/* Other application error codes */
124/// Call() execution error. This is clearly an application level error code,
125/// but we keep the error code to be ethereum rpc client compatible.
126pub const CALL_EXECUTION_ERROR: i64 = -32015;
127
128/* PoS chain is not started */
129pub const POS_NOT_ENABLED: i64 = -32078;