Skip to main content

Module error

Module error 

Source
Expand description

Error types and handling for the Schwab SDK.

All SDK operations return Result<T> which is an alias for std::result::Result<T, Error>. Each error variant includes recovery guidance for handling different failure scenarios.

§Error Recovery Strategies

§Transient Errors (Retryable)

§Permanent Errors (Don’t Retry)

§Trading Control Errors (Resolve the condition, then submit a new intent)

§Portability

Error::kind gives a stable, serializable ErrorKind for logging, metrics and policy decisions. ErrorEnvelope carries an error across a process boundary (the remote authority uses it) so the typed variants above survive the hop instead of collapsing into an opaque status code.

§Example

use rustyschwab::{Error, Result};
use std::{future::Future, time::Duration};

/// Honour one server-directed wait, then give up.
async fn with_rate_limit_retry<T, F, Fut>(mut call: F) -> Result<T>
where
    F: FnMut() -> Fut,
    Fut: Future<Output = Result<T>>,
{
    match call().await {
        // Rate limit: wait as told and try once more
        Err(Error::RateLimit { retry_after }) => {
            tokio::time::sleep(Duration::from_secs(retry_after)).await;
            call().await
        }
        // Configuration errors are the caller's to fix
        Err(Error::Config(msg)) => {
            eprintln!("Config error: {msg}");
            Err(Error::Config(msg))
        }
        // Everything else propagates
        other => other,
    }
}

Structs§

ApiError
One error from a Schwab error body; see crate::types::market_data::ApiError. One error from a Schwab error body ({"errors":[...]}).
ErrorEnvelope
Wire form of an Error with enough structure to rebuild the typed variant on the other side of a process boundary.
ErrorSource
One error from a Schwab error body; see crate::types::market_data::ApiError. Source location of an API error.

Enums§

AuthError
Error
Comprehensive error type for all SDK operations.
ErrorKind
Stable classification of an Error, independent of its payload.
StreamError

Functions§

parse_api_error
Parse a Schwab error body. Two shapes are documented: the market data API’s {"errors":[{"status","title","detail",...}]} and the trader API’s {"message":"...","errors":["..."]}; either becomes Error::Broker, so the reason reaches the caller. Anything else is Error::Http carrying the body.

Type Aliases§

Result
Standard result type for SDK operations.