Skip to main content

ma_core/
error.rs

1//! Error types for ma-core.
2
3use thiserror::Error;
4
5/// Errors returned by ma-core public APIs.
6#[derive(Debug, Error)]
7pub enum Error {
8    // ─── Transport ──────────────────────────────────────────────────────
9    #[error("transport error: {0}")]
10    Transport(String),
11
12    #[error("transport connect failed: {0}")]
13    Connect(String),
14
15    #[error("transport bind failed: {0}")]
16    Bind(String),
17
18    #[error("stream open failed: {0}")]
19    StreamOpen(String),
20
21    #[error("connection closed: {0}")]
22    ConnectionClosed(String),
23
24    // ─── Validation ─────────────────────────────────────────────────────
25    #[error("message validation failed: {0}")]
26    Validation(#[from] ma_did::MaError),
27
28    #[error("message signature verification failed")]
29    SignatureVerification,
30
31    #[error("replay detected for message {0}")]
32    Replay(String),
33
34    // ─── Resolution ─────────────────────────────────────────────────────
35    #[error("DID resolution failed for {did}: {detail}")]
36    Resolution { did: String, detail: String },
37
38    #[error("no inbox transport in DID document for {0}")]
39    NoInboxTransport(String),
40
41    #[error("invalid transport string: {0}")]
42    InvalidTransport(String),
43
44    // ─── Identity / key bootstrap ───────────────────────────────────────
45    #[error("secret key error: {0}")]
46    SecretKey(String),
47
48    #[error("endpoint ID derivation failed: {0}")]
49    EndpointId(String),
50
51    // ─── Config ─────────────────────────────────────────────────────────
52    #[cfg(feature = "config")]
53    #[error("config error: {0}")]
54    Config(String),
55
56    // ─── Secrets bundle ──────────────────────────────────────────────────
57    #[cfg(feature = "config")]
58    #[error("secrets error: {0}")]
59    Secrets(String),
60
61    // ─── ACL ─────────────────────────────────────────────────────────────
62    #[cfg(feature = "acl")]
63    #[error("acl error: {0}")]
64    Acl(String),
65
66    // ─── Service registration ───────────────────────────────────────────
67    #[error("duplicate service ALPN: {0}")]
68    DuplicateService(String),
69
70    // ─── Generic pass-through ───────────────────────────────────────────
71    #[error(transparent)]
72    Other(#[from] anyhow::Error),
73}
74
75pub type Result<T> = std::result::Result<T, Error>;