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)
Error::RateLimit- Wait and retry with exponential backoffError::Timeout- Retry with longer timeoutError::ConnectionClosed- Reconnect using built-in reconnect logic- HTTP 5xx errors (
Error::Http,Error::Broker,Error::Remote) - Retry with backoff (automatically handled by SDK)
§Permanent Errors (Don’t Retry)
Error::Auth- Re-authenticate with fresh OAuth flowError::InvalidParameter- Fix parameter valuesError::Config- Validate configuration settings- HTTP 4xx errors (except 429) - Fix request parameters
§Trading Control Errors (Resolve the condition, then submit a new intent)
Error::Halted- An operator halt is active; wait for the operator to lift itError::Suspended- Data recovery or a process drain paused submissions; nothing was sent, so retry shortlyError::RiskDenied- A risk policy rejected the order; adjust size or wait for exposure to fallError::BaselineStale- Reconcile the account, then resubmitError::Duplicate- The intent, tag or approval was already used; never resubmit blindlyError::ApprovalInvalid- Obtain a fresh operator approvalError::ReconciliationRequired/Error::SubmissionUnknown- Reconcile the pending attempt before submitting againError::OwnershipLost- Another writer holds the execution leaseError::LeaseBusy- Another operation held the lease for the whole wait; nothing was sent, so the same intent can be submitted again
§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":[...]}). - Error
Envelope - Wire form of an
Errorwith enough structure to rebuild the typed variant on the other side of a process boundary. - Error
Source - One error from a Schwab error body; see
crate::types::market_data::ApiError. Source location of an API error.
Enums§
- Auth
Error - Error
- Comprehensive error type for all SDK operations.
- Error
Kind - Stable classification of an
Error, independent of its payload. - Stream
Error
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 becomesError::Broker, so the reason reaches the caller. Anything else isError::Httpcarrying the body.
Type Aliases§
- Result
- Standard result type for SDK operations.