nautilus_dydx/
error.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2025 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
16//! Error handling for the dYdX adapter.
17//!
18//! This module provides error types for all dYdX operations, including
19//! HTTP, WebSocket, and gRPC errors.
20
21use thiserror::Error;
22
23/// Result type for dYdX operations.
24pub type DydxResult<T> = Result<T, DydxError>;
25
26/// The main error type for all dYdX adapter operations.
27#[derive(Debug, Error)]
28pub enum DydxError {
29    /// HTTP client errors.
30    #[error("HTTP error: {0}")]
31    Http(String),
32
33    /// WebSocket connection errors.
34    #[error("WebSocket error: {0}")]
35    WebSocket(String),
36
37    /// gRPC errors from Cosmos SDK node.
38    #[error("gRPC error: {0}")]
39    Grpc(#[from] tonic::Status),
40
41    /// Transaction signing errors.
42    #[error("Signing error: {0}")]
43    Signing(String),
44
45    /// Protocol buffer encoding errors.
46    #[error("Encoding error: {0}")]
47    Encoding(#[from] prost::EncodeError),
48
49    /// Protocol buffer decoding errors.
50    #[error("Decoding error: {0}")]
51    Decoding(#[from] prost::DecodeError),
52
53    /// JSON serialization/deserialization errors.
54    #[error("JSON error: {message}")]
55    Json {
56        message: String,
57        /// The raw JSON that failed to parse, if available.
58        raw: Option<String>,
59    },
60
61    /// Configuration errors.
62    #[error("Configuration error: {0}")]
63    Config(String),
64
65    /// Invalid data errors.
66    #[error("Invalid data: {0}")]
67    InvalidData(String),
68
69    /// Invalid order side error.
70    #[error("Invalid order side: {0}")]
71    InvalidOrderSide(String),
72
73    /// Unsupported order type error.
74    #[error("Unsupported order type: {0}")]
75    UnsupportedOrderType(String),
76
77    /// Feature not yet implemented.
78    #[error("Not implemented: {0}")]
79    NotImplemented(String),
80
81    /// Order construction and submission errors.
82    #[error("Order error: {0}")]
83    Order(String),
84
85    /// Nautilus core errors.
86    #[error("Nautilus error: {0}")]
87    Nautilus(#[from] anyhow::Error),
88}