db_core/
errors.rs

1// Copyright (C) 2022  Aravinth Manivannan <realaravinth@batsense.net>
2// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
3//
4// SPDX-License-Identifier: AGPL-3.0-or-later
5
6//! represents all the ways a trait can fail using this crate
7use std::error::Error as StdError;
8
9//use derive_more::{error, Error as DeriveError};
10use thiserror::Error;
11
12/// Error data structure grouping various error subtypes
13#[derive(Debug, Error)]
14pub enum DBError {
15    /// errors that are specific to a database implementation
16    #[error("{0}")]
17    DBError(#[source] BoxDynError),
18    /// Username is taken
19    #[error("Username is taken")]
20    UsernameTaken,
21    /// Email is taken
22    #[error("Email is taken")]
23    EmailTaken,
24    /// Secret is taken
25    #[error("Secret is taken")]
26    SecretTaken,
27    /// Captcha key is taken
28    #[error("Captcha key is taken")]
29    CaptchaKeyTaken,
30    /// Account not found
31    #[error("Account not found")]
32    AccountNotFound,
33
34    /// Captcha not found
35    #[error("Captcha not found")]
36    CaptchaNotFound,
37    /// Traffic pattern not found
38    #[error("Traffic pattern not found")]
39    TrafficPatternNotFound,
40
41    /// Notification not found
42    #[error("Notification not found")]
43    NotificationNotFound,
44}
45
46/// Convenience type alias for grouping driver-specific errors
47pub type BoxDynError = Box<dyn StdError + 'static + Send + Sync>;
48
49/// Generic result data structure
50pub type DBResult<V> = std::result::Result<V, DBError>;