Error

Enum Error 

Source
#[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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

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

§message: Cow<'static, str>

Error message

§retry_after: Option<Duration>

Optional duration to wait before retrying

§

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.

Fields

§context: String

Context message describing what operation failed

§source: Box<Error>

The underlying error

Implementations§

Source§

impl Error

Source

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");
Source

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.

Source

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);
Source

pub fn authentication(msg: impl Into<Cow<'static, str>>) -> Self

Creates an authentication error. Accepts both &'static str (zero allocation) and String.

Source

pub fn generic(msg: impl Into<Cow<'static, str>>) -> Self

Creates a generic error (for backwards compatibility).

Source

pub fn network(msg: impl Into<String>) -> Self

Creates a network error from a message.

Source

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.

Source

pub fn not_implemented(feature: impl Into<Cow<'static, str>>) -> Self

Creates a not implemented error. Accepts both &'static str (zero allocation) and String.

Source

pub fn invalid_request(msg: impl Into<Cow<'static, str>>) -> Self

Creates an invalid request error.

Source

pub fn invalid_argument(msg: impl Into<Cow<'static, str>>) -> Self

Creates an invalid argument error (alias for invalid_request).

Source

pub fn bad_symbol(symbol: impl Into<String>) -> Self

Creates a bad symbol error (alias for invalid_request).

Source

pub fn insufficient_balance(msg: impl Into<Cow<'static, str>>) -> Self

Creates an insufficient balance error.

Source

pub fn timeout(msg: impl Into<Cow<'static, str>>) -> Self

Creates a timeout error.

Source

pub fn websocket(msg: impl Into<String>) -> Self

Creates a WebSocket error from a message string.

Source

pub fn websocket_error<E: StdError + Send + Sync + 'static>(err: E) -> Self

Creates a WebSocket error from any error type.

Source

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");
Source

pub fn root_cause(&self) -> &Error

Returns the root cause of the error, skipping Context layers.

Source

pub fn find_variant<F>(&self, matcher: F) -> Option<&Error>
where F: Fn(&Error) -> bool,

Finds a specific error variant in the chain (penetrates Context layers). Useful for handling wrapped errors without manual unwrapping.

Source

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 refused
Source

pub fn is_retryable(&self) -> bool

Checks if this error is retryable (penetrates Context layers).

Returns true for:

  • NetworkError::Timeout
  • NetworkError::ConnectionFailed
  • RateLimit
  • Timeout
Source

pub fn retry_after(&self) -> Option<Duration>

Returns the retry delay if this is a rate limit error (penetrates Context layers).

Source

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.

Source

pub fn as_authentication(&self) -> Option<&str>

Checks if this is an authentication error (penetrates Context layers). Returns the error message.

Source

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>

Source§

fn context<C>(self, context: C) -> Result<T>
where C: Display + Send + Sync + 'static,

Adds context to an error.
Source§

fn with_context<C, F>(self, f: F) -> Result<T>
where C: Display + Send + Sync + 'static, F: FnOnce() -> C,

Adds lazy context to an error (only evaluated on error).
Source§

impl Debug for Error

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Error

Source§

fn fmt(&self, __formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for Error

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<Box<NetworkError>> for Error

Source§

fn from(e: Box<NetworkError>) -> Self

Converts to this type from the input type.
Source§

impl From<Box<OrderError>> for Error

Source§

fn from(e: Box<OrderError>) -> Self

Converts to this type from the input type.
Source§

impl From<Box<ParseError>> for Error

Source§

fn from(e: Box<ParseError>) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for Error

Source§

fn from(e: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for Error

Source§

fn from(e: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for Error

Source§

fn from(e: Error) -> Self

Converts to this type from the input type.
Source§

impl From<NetworkError> for Error

Source§

fn from(e: NetworkError) -> Self

Converts to this type from the input type.
Source§

impl From<OrderError> for Error

Source§

fn from(e: OrderError) -> Self

Converts to this type from the input type.
Source§

impl From<ParseError> for Error

Source§

fn from(e: ParseError) -> Self

Converts to this type from the input type.

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T> ToStringFallible for T
where T: Display,

Source§

fn try_to_string(&self) -> Result<String, TryReserveError>

ToString::to_string, but without panic on OOM.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more