2019-01-07 17:57:27 -08:00
|
|
|
use std::io;
|
2019-02-19 11:24:50 -08:00
|
|
|
use tree_sitter_highlight::PropertySheetError;
|
2019-01-07 17:57:27 -08:00
|
|
|
|
2018-12-05 12:50:12 -08:00
|
|
|
#[derive(Debug)]
|
2019-01-04 12:42:45 -08:00
|
|
|
pub struct Error(pub String);
|
2018-12-05 12:50:12 -08:00
|
|
|
|
|
|
|
|
pub type Result<T> = std::result::Result<T, Error>;
|
|
|
|
|
|
2018-12-08 13:44:11 -08:00
|
|
|
impl Error {
|
|
|
|
|
pub fn grammar(message: &str) -> Self {
|
2019-01-04 12:42:45 -08:00
|
|
|
Error(format!("Grammar error: {}", message))
|
2018-12-08 13:44:11 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn regex(message: &str) -> Self {
|
2019-01-04 12:42:45 -08:00
|
|
|
Error(format!("Regex error: {}", message))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn undefined_symbol(name: &str) -> Self {
|
|
|
|
|
Error(format!("Undefined symbol `{}`", name))
|
2018-12-08 13:44:11 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-05 12:50:12 -08:00
|
|
|
impl From<serde_json::Error> for Error {
|
|
|
|
|
fn from(error: serde_json::Error) -> Self {
|
2019-01-04 12:42:45 -08:00
|
|
|
Error(error.to_string())
|
2018-12-05 12:50:12 -08:00
|
|
|
}
|
|
|
|
|
}
|
2019-01-07 17:57:27 -08:00
|
|
|
|
|
|
|
|
impl From<io::Error> for Error {
|
|
|
|
|
fn from(error: io::Error) -> Self {
|
|
|
|
|
Error(error.to_string())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-09 18:09:55 -08:00
|
|
|
impl From<rsass::Error> for Error {
|
|
|
|
|
fn from(error: rsass::Error) -> Self {
|
|
|
|
|
Error(error.to_string())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-07 17:57:27 -08:00
|
|
|
impl From<String> for Error {
|
|
|
|
|
fn from(error: String) -> Self {
|
|
|
|
|
Error(error)
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-02-19 11:24:50 -08:00
|
|
|
|
|
|
|
|
impl From<PropertySheetError> for Error {
|
|
|
|
|
fn from(error: PropertySheetError) -> Self {
|
|
|
|
|
match error {
|
|
|
|
|
PropertySheetError::InvalidFormat(e) => Self::from(e),
|
|
|
|
|
PropertySheetError::InvalidRegex(e) => Self::regex(&e.to_string()),
|
|
|
|
|
PropertySheetError::InvalidJSON(e) => Self::from(e),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|