#[non_exhaustive]pub enum Error {
Show 15 variants
Exchange(Box<ExchangeErrorDetails>),
Network(Box<NetworkError>),
Authentication(Cow<'static, str>),
RateLimit {
message: Cow<'static, str>,
retry_after: Option<Duration>,
},
InvalidRequest(Cow<'static, str>),
Order(Box<OrderError>),
InsufficientBalance(Cow<'static, str>),
InvalidOrder(Cow<'static, str>),
OrderNotFound(Cow<'static, str>),
MarketNotFound(Cow<'static, str>),
Parse(Box<ParseError>),
WebSocket(Box<dyn StdError + Send + Sync + 'static>),
Timeout(Cow<'static, str>),
NotImplemented(Cow<'static, str>),
Context {
context: String,
source: Box<Error>,
},
}Expand description
The primary error type for the ccxt-rust library.
Design constraints:
- All large variants are boxed to keep enum size ≤ 56 bytes
- Uses
Cow<'static, str>for zero-allocation static strings - Verify with:
assert!(std::mem::size_of::<Error>() <= 56);
§Example
use ccxt_core::error::Error;
let err = Error::authentication("Invalid API key");
assert!(err.to_string().contains("Invalid API key"));Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Exchange(Box<ExchangeErrorDetails>)
Exchange-specific errors returned by the exchange API.
Boxed to reduce enum size (ExchangeErrorDetails is large).
Network(Box<NetworkError>)
Network-related errors encapsulating transport layer issues. Boxed to reduce enum size.
Authentication(Cow<'static, str>)
Authentication errors (invalid API key, signature, etc.).
RateLimit
Rate limit exceeded with optional retry information.
Fields
InvalidRequest(Cow<'static, str>)
Invalid request parameters.
Order(Box<OrderError>)
Order-related errors. Boxed to reduce enum size.
InsufficientBalance(Cow<'static, str>)
Insufficient balance for an operation.
InvalidOrder(Cow<'static, str>)
Invalid order format or parameters.
OrderNotFound(Cow<'static, str>)
Order not found on the exchange.
MarketNotFound(Cow<'static, str>)
Market symbol not found or not supported.
Parse(Box<ParseError>)
Errors during response parsing. Boxed to reduce enum size.
WebSocket(Box<dyn StdError + Send + Sync + 'static>)
WebSocket communication errors.
Uses Box<dyn StdError> to preserve original error for downcast.
Timeout(Cow<'static, str>)
Operation timeout.
NotImplemented(Cow<'static, str>)
Feature not implemented for this exchange.
Context
Error with additional context, preserving the error chain.
Implementations§
Source§impl Error
impl Error
Sourcepub fn exchange(code: impl Into<String>, message: impl Into<String>) -> Self
pub fn exchange(code: impl Into<String>, message: impl Into<String>) -> Self
Creates a new exchange error.
§Example
use ccxt_core::error::Error;
let err = Error::exchange("400", "Bad Request");Sourcepub fn exchange_with_data(
code: impl Into<String>,
message: impl Into<String>,
data: Value,
) -> Self
pub fn exchange_with_data( code: impl Into<String>, message: impl Into<String>, data: Value, ) -> Self
Creates a new exchange error with raw response data.
Sourcepub fn rate_limit(
message: impl Into<Cow<'static, str>>,
retry_after: Option<Duration>,
) -> Self
pub fn rate_limit( message: impl Into<Cow<'static, str>>, retry_after: Option<Duration>, ) -> Self
Creates a new rate limit error with optional retry duration.
Accepts both &'static str (zero allocation) and String.
§Example
use ccxt_core::error::Error;
use std::time::Duration;
// Zero allocation (static string):
let err = Error::rate_limit("Too many requests", Some(Duration::from_secs(60)));
// Allocation (dynamic string):
let err = Error::rate_limit(format!("Rate limit: {}", 429), None);Sourcepub fn authentication(msg: impl Into<Cow<'static, str>>) -> Self
pub fn authentication(msg: impl Into<Cow<'static, str>>) -> Self
Creates an authentication error.
Accepts both &'static str (zero allocation) and String.
Sourcepub fn generic(msg: impl Into<Cow<'static, str>>) -> Self
pub fn generic(msg: impl Into<Cow<'static, str>>) -> Self
Creates a generic error (for backwards compatibility).
Sourcepub fn market_not_found(symbol: impl Into<Cow<'static, str>>) -> Self
pub fn market_not_found(symbol: impl Into<Cow<'static, str>>) -> Self
Creates a market not found error.
Accepts both &'static str (zero allocation) and String.
Sourcepub fn not_implemented(feature: impl Into<Cow<'static, str>>) -> Self
pub fn not_implemented(feature: impl Into<Cow<'static, str>>) -> Self
Creates a not implemented error.
Accepts both &'static str (zero allocation) and String.
Sourcepub fn invalid_request(msg: impl Into<Cow<'static, str>>) -> Self
pub fn invalid_request(msg: impl Into<Cow<'static, str>>) -> Self
Creates an invalid request error.
Sourcepub fn invalid_argument(msg: impl Into<Cow<'static, str>>) -> Self
pub fn invalid_argument(msg: impl Into<Cow<'static, str>>) -> Self
Creates an invalid argument error (alias for invalid_request).
Sourcepub fn bad_symbol(symbol: impl Into<String>) -> Self
pub fn bad_symbol(symbol: impl Into<String>) -> Self
Creates a bad symbol error (alias for invalid_request).
Sourcepub fn insufficient_balance(msg: impl Into<Cow<'static, str>>) -> Self
pub fn insufficient_balance(msg: impl Into<Cow<'static, str>>) -> Self
Creates an insufficient balance error.
Sourcepub fn websocket(msg: impl Into<String>) -> Self
pub fn websocket(msg: impl Into<String>) -> Self
Creates a WebSocket error from a message string.
Sourcepub fn websocket_error<E: StdError + Send + Sync + 'static>(err: E) -> Self
pub fn websocket_error<E: StdError + Send + Sync + 'static>(err: E) -> Self
Creates a WebSocket error from any error type.
Sourcepub fn context(self, context: impl Into<String>) -> Self
pub fn context(self, context: impl Into<String>) -> Self
Attaches context to an existing error.
§Example
use ccxt_core::error::Error;
let err = Error::network("Connection refused")
.context("Failed to fetch ticker for BTC/USDT");Sourcepub fn root_cause(&self) -> &Error
pub fn root_cause(&self) -> &Error
Returns the root cause of the error, skipping Context layers.
Sourcepub fn find_variant<F>(&self, matcher: F) -> Option<&Error>
pub fn find_variant<F>(&self, matcher: F) -> Option<&Error>
Finds a specific error variant in the chain (penetrates Context layers). Useful for handling wrapped errors without manual unwrapping.
Sourcepub fn report(&self) -> String
pub fn report(&self) -> String
Generates a detailed error report with the full chain.
§Example
use ccxt_core::error::Error;
let err = Error::network("Connection refused")
.context("Failed to fetch ticker");
println!("{}", err.report());
// Output:
// Failed to fetch ticker
// Caused by: Network error: Connection failed: Connection refusedSourcepub fn is_retryable(&self) -> bool
pub fn is_retryable(&self) -> bool
Checks if this error is retryable (penetrates Context layers).
Returns true for:
NetworkError::TimeoutNetworkError::ConnectionFailedRateLimitTimeout
Sourcepub fn retry_after(&self) -> Option<Duration>
pub fn retry_after(&self) -> Option<Duration>
Returns the retry delay if this is a rate limit error (penetrates Context layers).
Sourcepub fn as_rate_limit(&self) -> Option<(&str, Option<Duration>)>
pub fn as_rate_limit(&self) -> Option<(&str, Option<Duration>)>
Checks if this is a rate limit error (penetrates Context layers). Returns the message and optional retry duration.
Sourcepub fn as_authentication(&self) -> Option<&str>
pub fn as_authentication(&self) -> Option<&str>
Checks if this is an authentication error (penetrates Context layers). Returns the error message.
Sourcepub fn downcast_websocket<T: StdError + 'static>(&self) -> Option<&T>
pub fn downcast_websocket<T: StdError + 'static>(&self) -> Option<&T>
Attempts to downcast the WebSocket error to a specific type.
Trait Implementations§
Source§impl<T> ContextExt<T, Error> for Option<T>
impl<T> ContextExt<T, Error> for Option<T>
Source§impl Error for Error
impl Error for Error
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
Source§impl From<Box<NetworkError>> for Error
impl From<Box<NetworkError>> for Error
Source§fn from(e: Box<NetworkError>) -> Self
fn from(e: Box<NetworkError>) -> Self
Source§impl From<Box<OrderError>> for Error
impl From<Box<OrderError>> for Error
Source§fn from(e: Box<OrderError>) -> Self
fn from(e: Box<OrderError>) -> Self
Source§impl From<Box<ParseError>> for Error
impl From<Box<ParseError>> for Error
Source§fn from(e: Box<ParseError>) -> Self
fn from(e: Box<ParseError>) -> Self
Source§impl From<NetworkError> for Error
impl From<NetworkError> for Error
Source§fn from(e: NetworkError) -> Self
fn from(e: NetworkError) -> Self
Source§impl From<OrderError> for Error
impl From<OrderError> for Error
Source§fn from(e: OrderError) -> Self
fn from(e: OrderError) -> Self
Source§impl From<ParseError> for Error
impl From<ParseError> for Error
Source§fn from(e: ParseError) -> Self
fn from(e: ParseError) -> Self
Auto Trait Implementations§
impl Freeze for Error
impl !RefUnwindSafe for Error
impl Send for Error
impl Sync for Error
impl Unpin for Error
impl !UnwindSafe for Error
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.