app_json_settings/core/
error.rs1use std::fmt;
2use std::io;
3
4#[derive(Debug)]
6pub enum ConfigError {
7 Io(io::Error),
9 Serialize(serde_json::Error),
11 Deserialize(serde_json::Error),
13 InvalidPathComponent(String),
15 Platform(String),
17}
18
19impl From<io::Error> for ConfigError {
20 fn from(e: io::Error) -> Self {
21 ConfigError::Io(e)
22 }
23}
24
25impl fmt::Display for ConfigError {
26 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
27 match self {
28 ConfigError::Io(e) => write!(f, "I/O error: {e}"),
29 ConfigError::Serialize(e) => write!(f, "JSON serialization error: {e}"),
30 ConfigError::Deserialize(e) => write!(f, "JSON deserialization error: {e}"),
31 ConfigError::InvalidPathComponent(value) => {
32 write!(f, "invalid path component: {value:?}")
33 }
34 ConfigError::Platform(e) => write!(f, "platform error: {e}"),
35 }
36 }
37}
38
39impl std::error::Error for ConfigError {
40 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
41 match self {
42 ConfigError::Io(e) => Some(e),
43 ConfigError::Serialize(e) | ConfigError::Deserialize(e) => Some(e),
44 ConfigError::InvalidPathComponent(_) | ConfigError::Platform(_) => None,
45 }
46 }
47}
48
49pub type Result<T> = std::result::Result<T, ConfigError>;