1use std::fmt;
2
3pub type Result<T> = std::result::Result<T, Error>;
5
6#[derive(Debug, Clone, PartialEq, Eq)]
9#[non_exhaustive]
10pub enum Error {
11 IllegalTransition {
14 from: &'static str,
15 to: &'static str,
16 },
17 Integrity { expected: String, actual: String },
19 NotFound { what: String },
21 Unauthorized,
23 Malformed { what: String },
25 Backend { detail: String },
28}
29
30impl fmt::Display for Error {
31 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
32 match self {
33 Error::IllegalTransition { from, to } => {
34 write!(f, "illegal state transition: {from} -> {to}")
35 }
36 Error::Integrity { expected, actual } => {
37 write!(
38 f,
39 "integrity check failed: expected {expected}, got {actual}"
40 )
41 }
42 Error::NotFound { what } => write!(f, "not found: {what}"),
43 Error::Unauthorized => f.write_str("unauthorized: a verified mID session is required"),
44 Error::Malformed { what } => write!(f, "malformed input: {what}"),
45 Error::Backend { detail } => write!(f, "backend error: {detail}"),
46 }
47 }
48}
49
50impl std::error::Error for Error {}