summaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2019-12-04 20:20:02 +0100
committerLaurenz <laurmaedje@gmail.com>2019-12-04 20:20:02 +0100
commitf72b1505bebf8d2fe1a60d386a3a3c3b67d4f903 (patch)
tree09fa7137a2bae5454e6f9cecc1936633c90965d4 /src/lib.rs
parent9fb31defd037a90bf8f9e38fa33acae23a70b269 (diff)
Unify error types ♾
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs43
1 files changed, 26 insertions, 17 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 7b6c4012..3369d01c 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -18,13 +18,15 @@ pub extern crate toddle;
use std::cell::RefCell;
use smallvec::smallvec;
+
use toddle::query::{FontLoader, FontProvider, SharedFontLoader};
+use toddle::Error as FontError;
use crate::func::Scope;
use crate::layout::{layout_tree, MultiLayout, LayoutContext};
use crate::layout::{LayoutAxes, LayoutAlignment, Axis, Alignment};
-use crate::layout::{LayoutError, LayoutResult, LayoutSpace};
-use crate::syntax::{SyntaxTree, parse, ParseContext, ParseError, ParseResult};
+use crate::layout::{LayoutResult, LayoutSpace};
+use crate::syntax::{parse, SyntaxTree, ParseContext, Span, ParseResult};
use crate::style::{LayoutStyle, PageStyle, TextStyle};
#[macro_use]
@@ -116,24 +118,31 @@ impl<'p> Typesetter<'p> {
}
}
-/// The general error type for typesetting.
-pub enum TypesetError {
- /// An error that occured in the parsing step.
- Parse(ParseError),
- /// An error that occured in the layouting step.
- Layout(LayoutError),
+/// The result type for typesetting.
+pub type TypesetResult<T> = Result<T, TypesetError>;
+
+/// The error type for typesetting.
+pub struct TypesetError {
+ message: String,
+ span: Option<Span>,
+}
+
+impl TypesetError {
+ /// Create a new typesetting error.
+ pub fn with_message(message: String) -> TypesetError {
+ TypesetError { message, span: None }
+ }
}
error_type! {
err: TypesetError,
- show: f => match err {
- TypesetError::Parse(e) => write!(f, "{}", e),
- TypesetError::Layout(e) => write!(f, "{}", e),
- },
- source: match err {
- TypesetError::Parse(e) => Some(e),
- TypesetError::Layout(e) => Some(e),
+ show: f => {
+ write!(f, "{}", err.message)?;
+ if let Some(span) = err.span {
+ write!(f, " at {}", span)?;
+ }
+ Ok(())
},
- from: (ParseError, TypesetError::Parse(err)),
- from: (LayoutError, TypesetError::Layout(err)),
+ from: (std::io::Error, TypesetError::with_message(err.to_string())),
+ from: (FontError, TypesetError::with_message(err.to_string())),
}