Skip to main content

nautilus_blockchain/rpc/
error.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2026 Nautech Systems Pty Ltd. All rights reserved.
3//  https://nautechsystems.io
4//
5//  Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6//  You may not use this file except in compliance with the License.
7//  You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
8//
9//  Unless required by applicable law or agreed to in writing, software
10//  distributed under the License is distributed on an "AS IS" BASIS,
11//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//  See the License for the specific language governing permissions and
13//  limitations under the License.
14// -------------------------------------------------------------------------------------------------
15
16use thiserror::Error;
17
18/// Represents errors that can occur when interacting with a blockchain RPC client.
19#[derive(Debug, Error)]
20pub enum BlockchainRpcClientError {
21    /// Occurs when the RPC client encounters a client-level error, such as connection failures.
22    #[error("Client error: {0}")]
23    ClientError(String),
24    /// Occurs when input parameters to an RPC call are invalid.
25    #[error("Invalid RPC parameters: {0}")]
26    InvalidParameters(String),
27    /// Occurs when decoding contract ABI data fails.
28    #[error("Decoding error: {0}")]
29    AbiDecodingError(String),
30    /// Occurs when parsing an RPC message fails.
31    #[error("Parsing error: {0}")]
32    MessageParsingError(String),
33    /// Occurs when receiving an unsupported RPC response type.
34    #[error("Unsupported rpc response type of message {0}")]
35    UnsupportedRpcResponseType(String),
36    /// Occurs when an internal RPC client error is encountered.
37    #[error("Internal Rpc client error: {0}")]
38    InternalRpcClientError(String),
39    /// Indicates that no message was received from the RPC channel.
40    #[error("No message received")]
41    NoMessageReceived,
42}
43
44/// Classifies `eth_sendRawTransaction` broadcast failures to determine retry behavior.
45#[derive(Debug, Error)]
46pub enum BroadcastError {
47    /// The request timed out after the transaction was sent; the node may have accepted it.
48    #[error("Broadcast timed out after send; the transaction may have been accepted by the node")]
49    TimeoutAfterSend,
50    /// The node definitively rejected the broadcast with an RPC error (sanitized: numeric code
51    /// only).
52    #[error("Broadcast rejected with RPC error {code}")]
53    Rejected {
54        /// The JSON-RPC error code returned by the node.
55        code: i32,
56    },
57    /// The broadcast failed in a way that leaves acceptance ambiguous (transport failure or an
58    /// unreadable response), conservatively treated as possibly accepted. Non-timeout transport
59    /// failures are deliberately bucketed here even though some (for example connection refused)
60    /// may never have reached the node: the HTTP client does not expose the connect-phase
61    /// distinction, and the conservative outcome reconciles through the persisted record instead
62    /// of rebroadcasting.
63    #[error("Broadcast failed ambiguously: {0}")]
64    Failed(String),
65}