forked from TeamHarTex/HarTex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror.rs
66 lines (57 loc) · 1.78 KB
/
error.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
* SPDX-License-Identifier: AGPL-3.0-only
*
* This file is part of HarTex.
*
* HarTex
* Copyright (c) 2021-2025 HarTex Project Developers
*
* HarTex is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* HarTex is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License along
* with HarTex. If not, see <https://www.gnu.org/licenses/>.
*/
//! # Entity Cache Errors
use std::env::VarError;
use std::error::Error;
use std::fmt;
use std::fmt::Display;
use std::fmt::Formatter;
use hartex_database_queries::result::Error as DatabaseError;
/// A cache error..
#[allow(clippy::module_name_repetitions)]
#[derive(Debug)]
pub enum CacheError {
/// Error related to environment variables.
Env(VarError),
/// A postgres error occurred.
Database(DatabaseError),
}
impl Display for CacheError {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
Self::Env(error) => writeln!(f, "env error: {error}"),
Self::Database(error) => writeln!(f, "database error: {error}"),
}
}
}
impl Error for CacheError {}
impl From<DatabaseError> for CacheError {
fn from(error: DatabaseError) -> Self {
Self::Database(error)
}
}
impl From<VarError> for CacheError {
fn from(error: VarError) -> Self {
Self::Env(error)
}
}
pub type CacheResult<T> = Result<T, CacheError>;