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
use crate::{de, ser};
use std::{fmt::Debug, path::PathBuf};
use thiserror::Error;
/// Defines the possible configuration errors.
#[derive(Error, Debug)]
pub enum Error {
/// Indicates a custom configuration error has occurred.
#[error("{0}")]
Custom(String),
/// Indicates an invalid configuration file has been provided.
#[error("{message}")]
InvalidFile {
/// Gets the error message.
message: String,
/// Gets the path of the file being loaded.
path: PathBuf,
},
/// Indicates a required configuration file is missing.
#[error("The configuration file '{0}' was not found, but is required.")]
MissingFile(PathBuf),
/// Indicates that a reification operation failed.
#[error(transparent)]
ReifyFailed(#[from] de::Error),
/// Indicates that a serialization operation failed.
#[error(transparent)]
SerializeFailed(#[from] ser::Error),
/// Indicates that an unknown [error](std::error::Error) occurred.
#[error(transparent)]
Unknown(#[from] Box<dyn std::error::Error + Send + Sync>),
}
impl Error {
/// Creates a new [custom](Self::Custom) error.
///
/// # Arguments
///
/// * `message` - The error message
#[inline]
pub fn custom(message: impl Into<String>) -> Self {
Self::Custom(message.into())
}
/// Creates a new [unknown](Self::Unknown) error.
///
/// # Arguments
///
/// * `error` - The unknown [error](std::error::Error)
#[inline]
pub fn unknown(error: impl std::error::Error + Send + Sync + 'static) -> Self {
Self::Unknown(Box::new(error))
}
}