dig_offers/error.rs
1//! The crate error taxonomy.
2//!
3//! Every fallible operation in dig-offers returns [`Result`], whose error is [`Error`]. The
4//! variants separate the failure sources a pure, key-free offer builder can hit: a lower-level
5//! driver failure while constructing a spend, a signer failure while computing the required
6//! signatures, a malformed `offer1…` string, a combine that merges two incompatible offers, and
7//! caller-supplied input that cannot produce a valid offer.
8
9use chia_wallet_sdk::driver::DriverError;
10use chia_wallet_sdk::signer::SignerError;
11
12/// The result of a dig-offers operation.
13pub type Result<T> = std::result::Result<T, Error>;
14
15/// Everything that can go wrong while building, taking, combining, cancelling, or inspecting a
16/// Chia offer.
17#[derive(Debug, thiserror::Error)]
18pub enum Error {
19 /// A failure in the underlying chia-wallet-sdk driver while constructing a spend
20 /// (allocation, currying, settlement assembly, coin selection inside the action system).
21 #[error("driver error: {0}")]
22 Driver(#[from] DriverError),
23
24 /// A failure while computing the BLS signatures a coin spend requires.
25 #[error("signer error: {0}")]
26 Signer(#[from] SignerError),
27
28 /// A malformed offer string: not a bech32 `offer1…`, or a payload that does not decode to a
29 /// valid offer spend bundle. The message states the precise fault.
30 #[error("decode error: {0}")]
31 Decode(String),
32
33 /// Two offers cannot be combined: they share an offered coin, or their asset metadata
34 /// conflicts. The message states the conflict.
35 #[error("incompatible offers: {0}")]
36 Incompatible(String),
37
38 /// Caller-supplied input that cannot produce a valid offer (an empty side, a zero requested
39 /// amount, or funds too small to cover what is offered/taken). The message states the
40 /// precise violation, including any shortfall.
41 #[error("invalid input: {0}")]
42 InvalidInput(String),
43}
44
45impl Error {
46 /// Construct an [`Error::InvalidInput`] from any displayable message.
47 pub(crate) fn invalid(message: impl Into<String>) -> Self {
48 Error::InvalidInput(message.into())
49 }
50
51 /// Construct an [`Error::Decode`] from any displayable message.
52 pub(crate) fn decode(message: impl Into<String>) -> Self {
53 Error::Decode(message.into())
54 }
55
56 /// Construct an [`Error::Incompatible`] from any displayable message.
57 pub(crate) fn incompatible(message: impl Into<String>) -> Self {
58 Error::Incompatible(message.into())
59 }
60}