beekeeper/errors.rs
1//! Error type returned by the public Rust API.
2//!
3//! A small enum rather than a single message string, so callers can
4//! pattern-match on the common cases without parsing error text.
5
6use thiserror::Error;
7
8/// Convenient `Result<T, BeekeeperError>` alias used internally.
9pub type Res<T> = Result<T, BeekeeperError>;
10
11/// Every failure surfaced by the Rust facade.
12///
13/// Errors raised by the C++ wallet manager arrive as
14/// [`cxx::Exception`] and are wrapped in
15/// [`BeekeeperError::Cxx`] verbatim — their `Display` message is the text
16/// thrown on the C++ side (typically an `fc::exception` message).
17#[derive(Debug, Error)]
18pub enum BeekeeperError {
19 /// The named wallet file is missing from the storage directory.
20 ///
21 /// Only emitted by [`RustStorageProtocol::cpp_load`](crate::storage::RustStorageProtocol),
22 /// i.e. when the C++ side asks for a wallet that does not exist on disk.
23 #[error("Wallet not found: {name}")]
24 WalletNotFound { name: String },
25
26 /// Persisting wallet bytes to disk failed (permissions, full disk, …).
27 #[error("Failed to write wallet: {name}")]
28 WalletWriteFailed { name: String },
29
30 /// A crypto primitive (AES, secp256k1, base58, …) refused the input.
31 ///
32 /// The wrapped string is the lower-level error's `Display` text.
33 #[error("Crypto error: {0}")]
34 Crypto(String),
35
36 /// An operation was attempted after the inactivity timeout elapsed.
37 #[error("Wallet locked due to timeout")]
38 TimedOut,
39
40 /// Pass-through for exceptions thrown by the C++ wallet manager.
41 #[error(transparent)]
42 Cxx(#[from] cxx::Exception),
43}