use std::error::Error;
use std::fmt::{Display, Formatter};
use crate::exceptions::ConfigurationException;
use crate::util::ValidateError;
#[derive(Debug)]
pub enum DialectSetConfigurationError {
IllegalArgument(ValidateError),
Configuration(ConfigurationException),
}
impl DialectSetConfigurationError {
#[must_use]
pub fn class_name(&self) -> &'static str {
match self {
Self::IllegalArgument(error) => error.class_name(),
Self::Configuration(_) => "org.thymeleaf.exceptions.ConfigurationException",
}
}
pub fn into_configuration_exception(self) -> ConfigurationException {
match self {
Self::Configuration(error) => error,
Self::IllegalArgument(error) => {
ConfigurationException::with_cause(Some(error.to_string()), error)
}
}
}
}
impl Display for DialectSetConfigurationError {
fn fmt(&self, formatter: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Self::IllegalArgument(error) => Display::fmt(error, formatter),
Self::Configuration(error) => Display::fmt(error, formatter),
}
}
}
impl Error for DialectSetConfigurationError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {
Self::IllegalArgument(error) => Some(error),
Self::Configuration(error) => Some(error),
}
}
}
impl From<ValidateError> for DialectSetConfigurationError {
fn from(error: ValidateError) -> Self {
Self::IllegalArgument(error)
}
}
impl From<ConfigurationException> for DialectSetConfigurationError {
fn from(error: ConfigurationException) -> Self {
Self::Configuration(error)
}
}