From 950158eaadd8db9ef0eb48187e825524499422d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Tue, 30 Mar 2021 12:36:53 +0200 Subject: config error --- mumlib/src/error.rs | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'mumlib/src/error.rs') diff --git a/mumlib/src/error.rs b/mumlib/src/error.rs index f6a02a7..6b7dccd 100644 --- a/mumlib/src/error.rs +++ b/mumlib/src/error.rs @@ -42,3 +42,42 @@ impl fmt::Display for ChannelIdentifierError { } } } + +pub enum ConfigError { + InvalidConfig, + TOMLErrorSer(toml::ser::Error), + TOMLErrorDe(toml::de::Error), + + WontCreateFile, + IOError(std::io::Error), +} + +impl fmt::Display for ConfigError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + ConfigError::InvalidConfig => write!(f, "Invalid configuration"), + ConfigError::TOMLErrorSer(e) => write!(f, "Invalid TOML when serializing: {}", e), + ConfigError::TOMLErrorDe(e) => write!(f, "Invalid TOML when deserializing: {}", e), + ConfigError::WontCreateFile => write!(f, "File does not exist but caller didn't allow creation"), + ConfigError::IOError(e) => write!(f, "IO error: {}", e), + } + } +} + +impl From for ConfigError { + fn from(e: std::io::Error) -> Self { + ConfigError::IOError(e) + } +} + +impl From for ConfigError { + fn from(e: toml::ser::Error) -> Self { + ConfigError::TOMLErrorSer(e) + } +} + +impl From for ConfigError { + fn from(e: toml::de::Error) -> Self { + ConfigError::TOMLErrorDe(e) + } +} -- cgit v1.2.1