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] did_ma::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    // ─── Service registration ───────────────────────────────────────────
52    #[error("duplicate service ALPN: {0}")]
53    DuplicateService(String),
54
55    // ─── Generic pass-through ───────────────────────────────────────────
56    #[error(transparent)]
57    Other(#[from] anyhow::Error),
58}
59
60pub type Result<T> = std::result::Result<T, Error>;