1use std::fmt::{Debug, Display, Formatter};
2use tokio::task::JoinError;
3
4#[derive(Debug)]
5#[non_exhaustive]
6pub enum Error {
8 Join(JoinError),
10 Argon(argon2::Error),
12 PasswordHash(password_hash::Error),
14 MissingConfig,
16}
17
18impl Display for Error {
19 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
20 f.write_str("error while hashing: ")?;
21 match self {
22 Error::Join(e) => write!(f, "tokio background thread errored: {}", e),
23 Error::Argon(e) => write!(f, "error in argon2 hashing algorithm: {}", e),
24 Error::PasswordHash(e) => write!(f, "error in password handling lib: {}", e),
25 Error::MissingConfig => f.write_str("global configuration has not been set"),
26 }
27 }
28}
29
30impl std::error::Error for Error {}
31
32impl From<JoinError> for Error {
33 fn from(e: JoinError) -> Self {
34 Self::Join(e)
35 }
36}
37
38impl From<argon2::Error> for Error {
39 fn from(e: argon2::Error) -> Self {
40 Self::Argon(e)
41 }
42}
43
44impl From<password_hash::Error> for Error {
45 fn from(e: password_hash::Error) -> Self {
46 Self::PasswordHash(e)
47 }
48}