From 52ccfa5a1bf2893bdc63ff1bad2b2a88ca86ef95 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Fri, 6 May 2022 09:56:18 +0300 Subject: refactor: replace SubplotError::JsonError with a more specific one SubplotError::JsonError is a generic error, but we actually only parse JSON when parsing the AST from Pandoc. Replace it with a ::AstJson error to be more specific, and hopefully more helpful to the user. Sponsored-by: author --- src/doc.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/doc.rs') diff --git a/src/doc.rs b/src/doc.rs index 71910f1..490a613 100644 --- a/src/doc.rs +++ b/src/doc.rs @@ -146,7 +146,7 @@ impl<'a> Document { P: AsRef + Debug, { trace!("Parsing document..."); - let ast: Pandoc = serde_json::from_str(json)?; + let ast: Pandoc = serde_json::from_str(json).map_err(SubplotError::AstJson)?; Self::from_ast(basedir, markdowns, ast, style, template) } @@ -217,7 +217,7 @@ impl<'a> Document { /// This is useful in a Pandoc filter, so that the filter can give /// it back to Pandoc for typesetting. pub fn ast(&self) -> Result { - let json = serde_json::to_string(&self.ast)?; + let json = serde_json::to_string(&self.ast).map_err(SubplotError::AstJson)?; Ok(json) } -- cgit v1.2.1