bp_core/
error.rs

1//! Unified error type for bp-core.
2//!
3//! All fallible functions in the library return [`BpResult<T>`], which is a
4//! type alias for `Result<T, BpError>`.  Callers can match on individual
5//! variants for fine-grained handling, or propagate with `?` and let `anyhow`
6//! or `thiserror` format a human-readable message.
7
8use thiserror::Error;
9
10/// Every error that can originate inside `bp-core`.
11///
12/// Uses `#[from]` blanket conversions for `std::io::Error` and
13/// `serde_json::Error` so that `?` works transparently on I/O and
14/// serialisation operations.
15#[derive(Debug, Error)]
16pub enum BpError {
17    /// Keypair generation, encoding, or decoding failed.
18    #[error("Identity error: {0}")]
19    Identity(String),
20
21    /// Invalid service type string or registry operation failed.
22    #[error("Service error: {0}")]
23    Service(String),
24
25    /// libp2p swarm or gossip operation failed.
26    #[error("Network error: {0}")]
27    Network(String),
28
29    /// Unix socket bind, accept, or I/O failed.
30    #[error("Control socket error: {0}")]
31    Control(String),
32
33    /// XDG path resolution failed (e.g. no home directory).
34    #[error("Config error: {0}")]
35    Config(String),
36
37    /// Storage directory, fragment I/O, or quota error.
38    #[error("Storage error: {0}")]
39    Storage(String),
40
41    /// RLNC encoding, decoding, or recoding error (e.g. singular matrix).
42    #[error("Coding error: {0}")]
43    Coding(String),
44
45    /// Transparent wrapper around [`std::io::Error`].
46    #[error("IO error: {0}")]
47    Io(#[from] std::io::Error),
48
49    /// Transparent wrapper around [`serde_json::Error`].
50    #[error("Serialization error: {0}")]
51    Serde(#[from] serde_json::Error),
52
53    /// The user has not yet run `bp login` — no keypair on disk.
54    #[error("Not authenticated — run `bp login` first")]
55    NotAuthenticated,
56
57    /// `bp hatch` has not been run — no daemon PID file or process found.
58    #[error("Daemon not running — run `bp hatch <service_type>` first")]
59    DaemonNotRunning,
60
61    /// A service UUID was referenced but is not in the registry.
62    #[error("Service not found: {0}")]
63    ServiceNotFound(String),
64
65    /// A network ID was referenced that this daemon has not joined.
66    #[error("Unknown network: {0}")]
67    UnknownNetwork(String),
68
69    /// An argument or parameter value is invalid (e.g. unknown tier name).
70    #[error("Invalid input: {0}")]
71    InvalidInput(String),
72}
73
74/// Convenience alias — all bp-core functions return this.
75pub type BpResult<T> = std::result::Result<T, BpError>;