Skip to main content

cow_errors/
lib.rs

1//! `cow-errors` — shared error type for the `CoW` Protocol SDK.
2//!
3//! [`CowError`] is the unified error type used across the workspace.
4//! Every fallible function in the SDK currently returns `Result<T, CowError>`.
5//!
6//! Per architecture rule 8 (errors per-domain + aggregation), this crate is
7//! a migration stopgap: future phases will split `CowError` into per-crate
8//! error types (`SigningError`, `OrderbookError`, ...) and aggregate them
9//! via a façade-level `SdkError`.
10//!
11//! # Variants
12//!
13//! | Variant | When |
14//! |---|---|
15//! | [`UnknownAsset`](CowError::UnknownAsset) | Asset symbol not in the token registry |
16//! | [`Api`](CowError::Api) | Orderbook/subgraph returned non-2xx |
17//! | [`Http`](CowError::Http) | Network transport failure |
18//! | [`Signing`](CowError::Signing) | ECDSA / EIP-712 signing failure |
19//! | [`Parse`](CowError::Parse) | Field parsing / deserialisation error |
20//! | [`AppData`](CowError::AppData) | App-data encoding / hashing failure |
21//! | [`Rpc`](CowError::Rpc) | JSON-RPC error from an Ethereum node |
22//! | [`Unsupported`](CowError::Unsupported) | Feature not available on chain/config |
23//! | [`Config`](CowError::Config) | SDK configuration error |
24//! | [`ZeroQuantity`](CowError::ZeroQuantity) | Trade amount is zero |
25
26#![deny(unsafe_code)]
27#![warn(missing_docs)]
28
29/// Errors that can occur when interacting with the `CoW` Protocol SDK.
30///
31/// This is the unified error type returned by every fallible function in
32/// the workspace. Each variant carries enough context to produce a useful
33/// diagnostic message via its [`Display`](std::fmt::Display) implementation.
34#[derive(Debug, thiserror::Error)]
35pub enum CowError {
36    /// The asset symbol is not in the token registry.
37    #[error("unknown asset: {0}")]
38    UnknownAsset(String),
39
40    /// The `CoW` Protocol API returned a non-2xx response.
41    #[error("cow api error {status}: {body}")]
42    Api {
43        /// HTTP status code.
44        status: u16,
45        /// Response body text.
46        body: String,
47    },
48
49    /// An HTTP transport error from `reqwest`.
50    #[error("http error: {0}")]
51    Http(#[from] reqwest::Error),
52
53    /// EIP-712 signing failed.
54    #[error("signing error: {0}")]
55    Signing(String),
56
57    /// The signal quantity is zero — nothing to trade.
58    #[error("signal quantity is zero")]
59    ZeroQuantity,
60
61    /// A required field in a quote or order response could not be parsed.
62    #[error("parse error for field '{field}': {reason}")]
63    Parse {
64        /// Field name that failed to parse.
65        field: &'static str,
66        /// Reason for the parse failure.
67        reason: String,
68    },
69
70    /// App-data encoding or hashing failed.
71    #[error("app-data error: {0}")]
72    AppData(String),
73
74    /// A JSON-RPC error returned by an Ethereum node.
75    #[error("rpc error {code}: {message}")]
76    Rpc {
77        /// JSON-RPC error code (e.g., `-32602` for invalid params).
78        code: i64,
79        /// Human-readable error description from the node.
80        message: String,
81    },
82
83    /// A feature or provider is not supported on the current chain or configuration.
84    #[error("unsupported: {message}")]
85    Unsupported {
86        /// Human-readable description of what is not supported.
87        message: String,
88    },
89
90    /// SDK configuration error (e.g. missing global adapter).
91    #[error("config error: {0}")]
92    Config(String),
93}