dig_options/error.rs
1//! The crate error taxonomy.
2//!
3//! Every fallible operation in dig-options returns [`Result`], whose error is [`Error`].
4//! The variants separate the three failure sources a pure builder can hit: a lower-level
5//! driver failure while constructing a spend, a signer failure while computing the required
6//! signatures, and caller-supplied input that cannot produce a valid spend.
7
8use chia_wallet_sdk::driver::DriverError;
9use chia_wallet_sdk::signer::SignerError;
10
11/// The result of a dig-options operation.
12pub type Result<T> = std::result::Result<T, Error>;
13
14/// Everything that can go wrong while building an option coin spend or reporting the
15/// signatures a coin spend requires.
16#[derive(Debug, thiserror::Error)]
17pub enum Error {
18 /// A failure in the underlying chia-wallet-sdk driver while constructing a spend
19 /// (allocation, currying, puzzle assembly, launcher mint).
20 #[error("driver error: {0}")]
21 Driver(#[from] DriverError),
22
23 /// A failure while computing the BLS signatures a coin spend requires.
24 #[error("signer error: {0}")]
25 Signer(#[from] SignerError),
26
27 /// Caller-supplied input that cannot produce a valid spend (e.g. a zero underlying
28 /// amount, an underfunded coin, a wrong-party clawback, or an unsupported strike type).
29 /// The message states the precise violation.
30 #[error("invalid input: {0}")]
31 InvalidInput(String),
32}
33
34impl Error {
35 /// Construct an [`Error::InvalidInput`] from any displayable message.
36 pub(crate) fn invalid(message: impl Into<String>) -> Self {
37 Error::InvalidInput(message.into())
38 }
39}