put errors in Box

This commit is contained in:
ConnorSkees 2020-06-26 05:12:28 -04:00
parent a04bc40129
commit f9be622eeb
3 changed files with 21 additions and 21 deletions

View File

@ -70,8 +70,8 @@ pub enum AtRuleKind {
} }
impl TryFrom<&Spanned<String>> for AtRuleKind { impl TryFrom<&Spanned<String>> for AtRuleKind {
type Error = SassError; type Error = Box<SassError>;
fn try_from(c: &Spanned<String>) -> Result<Self, SassError> { fn try_from(c: &Spanned<String>) -> Result<Self, Box<SassError>> {
Ok(match c.node.as_str() { Ok(match c.node.as_str() {
"use" => Self::Use, "use" => Self::Use,
"forward" => Self::Forward, "forward" => Self::Forward,

View File

@ -7,7 +7,7 @@ use std::{
use codemap::{Span, SpanLoc}; use codemap::{Span, SpanLoc};
pub type SassResult<T> = Result<T, SassError>; pub type SassResult<T> = Result<T, Box<SassError>>;
#[derive(Debug)] #[derive(Debug)]
pub struct SassError { 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] #[inline]
fn from(error: io::Error) -> Self { fn from(error: io::Error) -> Box<SassError> {
SassError { Box::new(SassError {
kind: SassErrorKind::IoError(error), kind: SassErrorKind::IoError(error),
} })
} }
} }
impl From<FromUtf8Error> for SassError { impl From<FromUtf8Error> for Box<SassError> {
#[inline] #[inline]
fn from(error: FromUtf8Error) -> Self { fn from(error: FromUtf8Error) -> Box<SassError> {
SassError { Box::new(SassError {
kind: SassErrorKind::FromUtf8Error(format!( kind: SassErrorKind::FromUtf8Error(format!(
"Invalid UTF-8 character \"\\x{:X?}\"", "Invalid UTF-8 character \"\\x{:X?}\"",
error.as_bytes()[0] error.as_bytes()[0]
)), )),
} })
} }
} }
impl From<(&str, Span)> for SassError { impl From<(&str, Span)> for Box<SassError> {
#[inline] #[inline]
fn from(error: (&str, Span)) -> SassError { fn from(error: (&str, Span)) -> Box<SassError> {
SassError { Box::new(SassError {
kind: SassErrorKind::Raw(error.0.to_owned(), error.1), kind: SassErrorKind::Raw(error.0.to_owned(), error.1),
} })
} }
} }
impl From<(String, Span)> for SassError { impl From<(String, Span)> for Box<SassError> {
#[inline] #[inline]
fn from(error: (String, Span)) -> SassError { fn from(error: (String, Span)) -> Box<SassError> {
SassError { Box::new(SassError {
kind: SassErrorKind::Raw(error.0, error.1), kind: SassErrorKind::Raw(error.0, error.1),
} })
} }
} }

View File

@ -126,9 +126,9 @@ mod unit;
mod utils; mod utils;
mod value; 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(); 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 /// Write CSS to `buf`, constructed from a path