ant_protocol/error.rs
1//! Error and `Result` types for `ant-protocol`.
2//!
3//! Kept intentionally small: this crate is a wire contract, so the only
4//! errors worth reifying are payment-construction failures and wallet
5//! I/O errors surfaced by `SingleNodePayment::{pay, verify}`.
6//!
7//! Callers that embed this crate (the node, the client) keep their own
8//! broader error enums and convert via `From<ant_protocol::Error>`.
9
10use std::fmt;
11
12/// Result alias used throughout this crate.
13pub type Result<T> = std::result::Result<T, Error>;
14
15/// Errors that can be produced by `ant-protocol` APIs that do I/O or
16/// construct payment proofs.
17///
18/// Wire-format errors (serialize/deserialize, size limits, address
19/// mismatches) are reported via [`crate::chunk::ProtocolError`] because
20/// they travel across the wire inside response messages.
21#[derive(Debug)]
22#[non_exhaustive]
23pub enum Error {
24 /// A payment-construction or on-chain interaction failed.
25 Payment(String),
26 /// A cryptographic operation failed (key parsing, signing probe).
27 Crypto(String),
28}
29
30impl fmt::Display for Error {
31 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
32 match self {
33 Self::Payment(msg) => write!(f, "payment error: {msg}"),
34 Self::Crypto(msg) => write!(f, "crypto error: {msg}"),
35 }
36 }
37}
38
39impl std::error::Error for Error {}