Skip to main content

m4a_agent/
error.rs

1use std::fmt;
2
3/// Everything the client can fail at. Messages never contain key material or tokens.
4#[derive(Debug)]
5pub enum AgentError {
6    /// The vault could not be read or written.
7    Vault(String),
8    /// The stored identity is unusable or does not match what the session asked for.
9    Identity(String),
10    /// The network round trip failed.
11    Transport(String),
12    /// The server refused the proof (unknown key, spent or expired challenge, wrong audience, ...).
13    Refused(String),
14    /// The server answered something the client does not understand.
15    Protocol(String),
16    /// The host's own store (where sealed records live) failed.
17    Store(String),
18    /// The engine rejected what the server sent.
19    Ingest(String),
20    /// Not enrolled yet and no invite was given.
21    NeedsInvite,
22}
23
24impl fmt::Display for AgentError {
25    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
26        match self {
27            Self::Vault(m) => write!(f, "vault: {m}"),
28            Self::Identity(m) => write!(f, "identity: {m}"),
29            Self::Transport(m) => write!(f, "transport: {m}"),
30            Self::Refused(m) => write!(f, "refused: {m}"),
31            Self::Protocol(m) => write!(f, "protocol: {m}"),
32            Self::Store(m) => write!(f, "store: {m}"),
33            Self::Ingest(m) => write!(f, "ingest: {m}"),
34            Self::NeedsInvite => write!(f, "this identity is not enrolled yet: the operator must give an invite"),
35        }
36    }
37}
38
39impl std::error::Error for AgentError {}
40
41pub type Result<T> = std::result::Result<T, AgentError>;