use std;
use backend::*;
use format::Format;
#[cfg(feature = "xml")]
use failure::SyncFailure;
#[derive(Debug, Fail)]
pub enum Error {
#[cfg(feature = "json")]
#[fail(display = "JSON error: {}", _0)]
Json(#[fail(cause)] serde_json::Error),
#[cfg(feature = "yaml")]
#[fail(display = "YAML error: {}", _0)]
Yaml(#[fail(cause)] serde_yaml::Error),
#[cfg(feature = "toml")]
#[fail(display = "TOML deserialize error: {}", _0)]
TomlDeserialize(#[fail(cause)] toml::de::Error),
#[cfg(feature = "toml")]
#[fail(display = "TOML serialize error: {}", _0)]
TomlSerialize(#[fail(cause)] toml::ser::Error),
#[cfg(feature = "ron")]
#[fail(display = "RON deserialize error: {}", _0)]
RonDeserialize(#[fail(cause)] ron::de::Error),
#[cfg(feature = "ron")]
#[fail(display = "RON serialize error: {}", _0)]
RonSerialize(#[fail(cause)] ron::ser::Error),
#[cfg(feature = "xml")]
#[fail(display = "XML error: {}", _0)]
Xml(#[fail(cause)] SyncFailure<xml::Error>),
#[cfg(feature = "url")]
#[fail(display = "URL deserialize error: {}", _0)]
UrlDeserialize(#[fail(cause)] url::de::Error),
#[cfg(feature = "url")]
#[fail(display = "URL serialize error: {}", _0)]
UrlSerialize(#[fail(cause)] url::ser::Error),
#[fail(display = "IO error: {}", _0)]
Io(#[fail(cause)] std::io::Error),
#[fail(display = "Format {} not supported", _0)]
UnsupportedFormat(Format),
#[fail(display = "File extension {} not supported", _0)]
UnsupportedFileExtension(String),
#[fail(display = "No format was able to parse the source")]
NoSuccessfulParse(Vec<(Format, Error)>),
}
macro_rules! impl_error_from {
($error_type:ty => $variant:expr) => (
impl From<$error_type> for Error {
fn from(e: $error_type) -> Error {
$variant(e)
}
}
);
}
impl_error_from!(std::io::Error => Error::Io);
#[cfg(feature = "json")]
impl_error_from!(serde_json::Error => Error::Json);
#[cfg(feature = "yaml")]
impl_error_from!(serde_yaml::Error => Error::Yaml);
#[cfg(feature = "toml")]
impl_error_from!(toml::ser::Error => Error::TomlSerialize);
#[cfg(feature = "toml")]
impl_error_from!(toml::de::Error => Error::TomlDeserialize);
#[cfg(feature = "ron")]
impl_error_from!(ron::ser::Error => Error::RonSerialize);
#[cfg(feature = "ron")]
impl_error_from!(ron::de::Error => Error::RonDeserialize);
#[cfg(feature = "xml")]
impl From<xml::Error> for Error {
fn from(e: xml::Error) -> Error {
Error::Xml(SyncFailure::new(e))
}
}
#[cfg(feature = "url")]
impl_error_from!(url::ser::Error => Error::UrlSerialize);
#[cfg(feature = "url")]
impl_error_from!(url::de::Error => Error::UrlDeserialize);