From f72b1505bebf8d2fe1a60d386a3a3c3b67d4f903 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Wed, 4 Dec 2019 20:20:02 +0100 Subject: =?UTF-8?q?Unify=20error=20types=20=E2=99=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layout/flex.rs | 3 ++- src/layout/mod.rs | 21 ++------------------- src/layout/stack.rs | 3 ++- src/layout/text.rs | 2 +- src/layout/tree.rs | 2 +- 5 files changed, 8 insertions(+), 23 deletions(-) (limited to 'src/layout') diff --git a/src/layout/flex.rs b/src/layout/flex.rs index 3e8a64e1..46d66951 100644 --- a/src/layout/flex.rs +++ b/src/layout/flex.rs @@ -230,7 +230,8 @@ impl FlexLayouter { while size.x > self.line.usable { if self.stack.space_is_last() { - lr!("box does not fit into line"); + error!("box of size {} does not fit into line of size {}", + size.x, self.line.usable); } self.stack.finish_space(true); diff --git a/src/layout/mod.rs b/src/layout/mod.rs index 4304e46e..690e91b7 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -5,8 +5,8 @@ use std::io::{self, Write}; use smallvec::SmallVec; use toddle::query::{FontClass, SharedFontLoader}; -use toddle::Error as FontError; +use crate::TypesetResult; use crate::func::Command; use crate::size::{Size, Size2D, SizeBox}; use crate::style::{LayoutStyle, TextStyle}; @@ -366,22 +366,5 @@ impl Serialize for MultiLayout { } } -/// The error type for layouting. -pub struct LayoutError(String); - /// The result type for layouting. -pub type LayoutResult = Result; - -impl LayoutError { - /// Create a new layout error with a message. - pub fn new>(message: S) -> LayoutError { - LayoutError(message.into()) - } -} - -error_type! { - err: LayoutError, - show: f => f.write_str(&err.0), - from: (std::io::Error, LayoutError::new(err.to_string())), - from: (FontError, LayoutError::new(err.to_string())), -} +pub type LayoutResult = TypesetResult; diff --git a/src/layout/stack.rs b/src/layout/stack.rs index 64823b67..176aa261 100644 --- a/src/layout/stack.rs +++ b/src/layout/stack.rs @@ -108,7 +108,8 @@ impl StackLayouter { // Find the first (sub-)space that fits the layout. while !self.sub.usable.fits(new_size) { if self.space_is_last() && self.space_is_empty() { - lr!("box does not fit into stack"); + error!("box of size {} does not fit into remaining stack of size {}", + size, self.sub.usable - Size2D::with_y(self.sub.size.y)); } self.finish_space(true); diff --git a/src/layout/text.rs b/src/layout/text.rs index 514bfe92..8a0e7cec 100644 --- a/src/layout/text.rs +++ b/src/layout/text.rs @@ -116,6 +116,6 @@ impl<'a, 'p> TextLayouter<'a, 'p> { self.classes.pop(); } - lr!("no suitable font for character `{}`", c); + error!("no suitable font for character `{}`", c); } } diff --git a/src/layout/tree.rs b/src/layout/tree.rs index 5fe3b6fd..c9d40e93 100644 --- a/src/layout/tree.rs +++ b/src/layout/tree.rs @@ -111,7 +111,7 @@ impl<'a, 'p> TreeLayouter<'a, 'p> { SetTextStyle(style) => self.style.text = style, SetPageStyle(style) => { if !self.ctx.top_level { - lr!("page style cannot only be altered in the top-level context"); + error!("the page style cannot only be altered from a top-level context"); } self.style.page = style; -- cgit v1.2.3