Skip to main content

Error

Enum Error 

Source
#[non_exhaustive]
pub enum Error {
Show 18 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 Error + Send + Sync>), Timeout(Cow<'static, str>), NotImplemented(Cow<'static, str>), Cancelled(Cow<'static, str>), ResourceExhausted(Cow<'static, str>), ConfigValidation(Box<ConfigValidationError>), 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 Error + Send + Sync>)

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.

§

Cancelled(Cow<'static, str>)

Operation was cancelled.

This error is returned when an operation is cancelled via a CancellationToken or other cancellation mechanism. It indicates that the operation was intentionally aborted and did not complete.

§Example

use ccxt_core::error::Error;

let err = Error::cancelled("WebSocket connection cancelled");
assert!(err.to_string().contains("cancelled"));
§

ResourceExhausted(Cow<'static, str>)

Resource exhausted error.

This error is returned when a resource limit has been reached, such as maximum number of WebSocket subscriptions, connection pool exhaustion, or other capacity limits.

§Example

use ccxt_core::error::Error;

let err = Error::resource_exhausted("Maximum subscriptions (100) reached");
assert!(err.to_string().contains("Resource exhausted"));
§

ConfigValidation(Box<ConfigValidationError>)

Configuration validation error.

This error is returned when configuration parameters fail validation, such as values being out of range or missing required fields. Boxed to reduce enum size.

§Example

use ccxt_core::error::{Error, ConfigValidationError};

let err = Error::config_validation(ConfigValidationError::too_high("max_retries", 15, 10));
assert!(err.to_string().contains("Configuration error"));
§

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>) -> Error

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, ) -> Error

Creates a new exchange error with raw response data.

Source

pub fn rate_limit( message: impl Into<Cow<'static, str>>, retry_after: Option<Duration>, ) -> Error

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>>) -> Error

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

Source

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

Creates a generic error (for backwards compatibility).

Source

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

Creates a network error from a message.

Source

pub fn market_not_found(symbol: impl Into<Cow<'static, str>>) -> Error

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>>) -> Error

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

Source

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

Creates a cancelled error.

Use this when an operation is cancelled via a CancellationToken or other cancellation mechanism.

Accepts both &'static str (zero allocation) and String.

§Example
use ccxt_core::error::Error;

// Zero allocation (static string):
let err = Error::cancelled("Operation cancelled by user");

// Allocation (dynamic string):
let err = Error::cancelled(format!("Connection {} cancelled", "ws-1"));
Source

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

Creates a resource exhausted error.

Use this when a resource limit has been reached, such as maximum WebSocket subscriptions, connection pool exhaustion, or other capacity limits.

Accepts both &'static str (zero allocation) and String.

§Example
use ccxt_core::error::Error;

// Zero allocation (static string):
let err = Error::resource_exhausted("Maximum subscriptions reached");

// Allocation (dynamic string):
let err = Error::resource_exhausted(format!("Maximum subscriptions ({}) reached", 100));
Source

pub fn config_validation(err: ConfigValidationError) -> Error

Creates a configuration validation error.

Use this when configuration parameters fail validation.

§Example
use ccxt_core::error::{Error, ConfigValidationError};

let err = Error::config_validation(ConfigValidationError::too_high("max_retries", 15, 10));
assert!(err.to_string().contains("Configuration error"));
Source

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

Creates an invalid request error.

Source

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

Creates an invalid argument error (alias for invalid_request).

Source

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

Creates a bad symbol error (alias for invalid_request).

Source

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

Creates an insufficient balance error.

Source

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

Creates a timeout error.

Source

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

Creates a WebSocket error from a message string.

Source

pub fn websocket_error<E>(err: E) -> Error
where E: Error + Send + Sync + 'static,

Creates a WebSocket error from any error type.

Source

pub fn context(self, context: impl Into<String>) -> Error

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 as_cancelled(&self) -> Option<&str>

Checks if this is a cancelled error (penetrates Context layers). Returns the error message.

§Example
use ccxt_core::error::Error;

let err = Error::cancelled("Operation cancelled");
assert_eq!(err.as_cancelled(), Some("Operation cancelled"));

// Works through context layers
let wrapped = err.context("Wrapped error");
assert_eq!(wrapped.as_cancelled(), Some("Operation cancelled"));
Source

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

Checks if this is a resource exhausted error (penetrates Context layers). Returns the error message.

§Example
use ccxt_core::error::Error;

let err = Error::resource_exhausted("Maximum subscriptions reached");
assert_eq!(err.as_resource_exhausted(), Some("Maximum subscriptions reached"));

// Works through context layers
let wrapped = err.context("Wrapped error");
assert_eq!(wrapped.as_resource_exhausted(), Some("Maximum subscriptions reached"));
Source

pub fn as_config_validation(&self) -> Option<&ConfigValidationError>

Checks if this is a configuration validation error (penetrates Context layers). Returns a reference to the ConfigValidationError.

§Example
use ccxt_core::error::{Error, ConfigValidationError};

let err = Error::config_validation(ConfigValidationError::too_high("max_retries", 15, 10));
assert!(err.as_config_validation().is_some());

// Works through context layers
let wrapped = err.context("Wrapped error");
assert!(wrapped.as_config_validation().is_some());
Source

pub fn downcast_websocket<T>(&self) -> Option<&T>
where T: Error + 'static,

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, Error>
where C: Display + Send + Sync + 'static,

Adds context to an error.
Source§

fn with_context<C, F>(self, f: F) -> Result<T, Error>
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<(), Error>

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

impl Display for Error

Source§

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

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<BinanceWsError> for Error

Conversion from BinanceWsError to CoreError.

This implementation allows Binance-specific errors to be returned from public API methods that return CoreError. The conversion preserves the original error for downcast capability.

§Conversion Rules

  • BinanceWsError::Core(core) → Returns the inner CoreError directly
  • All other variants → Boxed into CoreError::WebSocket for downcast
Source§

fn from(e: BinanceWsError) -> Error

Converts to this type from the input type.
Source§

impl From<Box<ConfigValidationError>> for Error

Source§

fn from(e: Box<ConfigValidationError>) -> Error

Converts to this type from the input type.
Source§

impl From<Box<NetworkError>> for Error

Source§

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

Converts to this type from the input type.
Source§

impl From<Box<OrderError>> for Error

Source§

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

Converts to this type from the input type.
Source§

impl From<Box<ParseError>> for Error

Source§

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

Converts to this type from the input type.
Source§

impl From<ConfigValidationError> for Error

Source§

fn from(e: ConfigValidationError) -> Error

Converts to this type from the input type.
Source§

impl From<Error> for Error

Source§

fn from(e: Error) -> Error

Converts to this type from the input type.
Source§

impl From<Error> for Error

Source§

fn from(e: Error) -> Error

Converts to this type from the input type.
Source§

impl From<Error> for Error

Source§

fn from(e: Error) -> Error

Converts to this type from the input type.
Source§

impl From<HyperLiquidErrorCode> for Error

Source§

fn from(code: HyperLiquidErrorCode) -> Error

Converts to this type from the input type.
Source§

impl From<NetworkError> for Error

Source§

fn from(e: NetworkError) -> Error

Converts to this type from the input type.
Source§

impl From<OrderError> for Error

Source§

fn from(e: OrderError) -> Error

Converts to this type from the input type.
Source§

impl From<ParseError> for Error

Source§

fn from(e: ParseError) -> Error

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