use crate::template::syntax::syntax_parse_error::SyntaxParseError as ParseError;
use crate::template::argument_types_differ_error::ArgumentTypesDifferError;
use std::error::Error;
use std::fmt;
#[derive(Debug)]
pub enum BuildError {
Parse(ParseError),
FunctionNotFound(String),
ArgumentsLengthDiffer(String),
ArgumentTypeNotMatch(ArgumentTypesDifferError),
}
impl From<ParseError> for BuildError {
fn from(error: ParseError) -> Self {
return BuildError::Parse(error);
}
}
impl From<ArgumentTypesDifferError> for BuildError {
fn from(error: ArgumentTypesDifferError) -> Self {
return BuildError::ArgumentTypeNotMatch(error);
}
}
impl fmt::Display for BuildError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
BuildError::Parse(ref error) => {
write!(f, "{}", error)
},
BuildError::FunctionNotFound(ref function_name) => {
write!(f, "Function with name `{}` not found", function_name)
},
BuildError::ArgumentsLengthDiffer(ref function_name) => {
write!(f, "Into function `{}` passed arguments with wrong length", function_name)
},
BuildError::ArgumentTypeNotMatch(ref error) => {
write!(f, "Argument with index `{}` at function `{}` has wrong type", error.get_argument_position(), error.get_function_name())
},
}
}
}
impl Error for BuildError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {
BuildError::Parse(ref error) => {
Some(error)
},
BuildError::FunctionNotFound(..) => {
None
},
BuildError::ArgumentsLengthDiffer(..) => {
None
},
BuildError::ArgumentTypeNotMatch(..) => {
None
},
}
}
}