put errors in Box
This commit is contained in:
parent
a04bc40129
commit
f9be622eeb
@ -70,8 +70,8 @@ pub enum AtRuleKind {
|
||||
}
|
||||
|
||||
impl TryFrom<&Spanned<String>> for AtRuleKind {
|
||||
type Error = SassError;
|
||||
fn try_from(c: &Spanned<String>) -> Result<Self, SassError> {
|
||||
type Error = Box<SassError>;
|
||||
fn try_from(c: &Spanned<String>) -> Result<Self, Box<SassError>> {
|
||||
Ok(match c.node.as_str() {
|
||||
"use" => Self::Use,
|
||||
"forward" => Self::Forward,
|
||||
|
34
src/error.rs
34
src/error.rs
@ -7,7 +7,7 @@ use std::{
|
||||
|
||||
use codemap::{Span, SpanLoc};
|
||||
|
||||
pub type SassResult<T> = Result<T, SassError>;
|
||||
pub type SassResult<T> = Result<T, Box<SassError>>;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct SassError {
|
||||
@ -78,42 +78,42 @@ impl Display for SassError {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<io::Error> for SassError {
|
||||
impl From<io::Error> for Box<SassError> {
|
||||
#[inline]
|
||||
fn from(error: io::Error) -> Self {
|
||||
SassError {
|
||||
fn from(error: io::Error) -> Box<SassError> {
|
||||
Box::new(SassError {
|
||||
kind: SassErrorKind::IoError(error),
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl From<FromUtf8Error> for SassError {
|
||||
impl From<FromUtf8Error> for Box<SassError> {
|
||||
#[inline]
|
||||
fn from(error: FromUtf8Error) -> Self {
|
||||
SassError {
|
||||
fn from(error: FromUtf8Error) -> Box<SassError> {
|
||||
Box::new(SassError {
|
||||
kind: SassErrorKind::FromUtf8Error(format!(
|
||||
"Invalid UTF-8 character \"\\x{:X?}\"",
|
||||
error.as_bytes()[0]
|
||||
)),
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl From<(&str, Span)> for SassError {
|
||||
impl From<(&str, Span)> for Box<SassError> {
|
||||
#[inline]
|
||||
fn from(error: (&str, Span)) -> SassError {
|
||||
SassError {
|
||||
fn from(error: (&str, Span)) -> Box<SassError> {
|
||||
Box::new(SassError {
|
||||
kind: SassErrorKind::Raw(error.0.to_owned(), error.1),
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl From<(String, Span)> for SassError {
|
||||
impl From<(String, Span)> for Box<SassError> {
|
||||
#[inline]
|
||||
fn from(error: (String, Span)) -> SassError {
|
||||
SassError {
|
||||
fn from(error: (String, Span)) -> Box<SassError> {
|
||||
Box::new(SassError {
|
||||
kind: SassErrorKind::Raw(error.0, error.1),
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -126,9 +126,9 @@ mod unit;
|
||||
mod utils;
|
||||
mod value;
|
||||
|
||||
fn raw_to_parse_error(map: &CodeMap, err: Error) -> Error {
|
||||
fn raw_to_parse_error(map: &CodeMap, err: Box<Error>) -> Box<Error> {
|
||||
let (message, span) = err.raw();
|
||||
Error::from_loc(message, map.look_up_span(span))
|
||||
Box::new(Error::from_loc(message, map.look_up_span(span)))
|
||||
}
|
||||
|
||||
/// Write CSS to `buf`, constructed from a path
|
||||
|
Loading…
x
Reference in New Issue
Block a user