2020-01-06 18:26:07 -05:00
|
|
|
use crate::common::Pos;
|
|
|
|
use std::error::Error;
|
|
|
|
use std::fmt::{self, Display};
|
|
|
|
use std::io;
|
2020-01-04 22:55:04 -05:00
|
|
|
|
2020-01-06 18:26:07 -05:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct SassError {
|
|
|
|
message: String,
|
2020-01-06 19:23:52 -05:00
|
|
|
pos: Pos,
|
2020-01-06 18:26:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
impl SassError {
|
|
|
|
pub fn new<S: Into<String>>(message: S, pos: Pos) -> Self {
|
2020-01-06 19:23:52 -05:00
|
|
|
SassError {
|
|
|
|
message: message.into(),
|
|
|
|
pos,
|
|
|
|
}
|
2020-01-06 18:26:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn unexpected_eof(pos: Pos) -> Self {
|
2020-01-06 19:23:52 -05:00
|
|
|
SassError {
|
|
|
|
message: String::from("unexpected eof"),
|
|
|
|
pos,
|
|
|
|
}
|
2020-01-06 18:26:07 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Display for SassError {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
write!(f, "error: {} at {}", self.message, self.pos)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<io::Error> for SassError {
|
|
|
|
fn from(error: io::Error) -> Self {
|
2020-01-06 19:23:52 -05:00
|
|
|
SassError {
|
|
|
|
pos: Pos::new(),
|
|
|
|
message: format!("{}", error),
|
|
|
|
}
|
2020-01-06 18:26:07 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Error for SassError {
|
|
|
|
fn description(&self) -> &'static str {
|
|
|
|
"SASS parsing error"
|
|
|
|
}
|
|
|
|
}
|