summaryrefslogtreecommitdiff
path: root/src/doc.rs
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2022-05-06 09:56:18 +0300
committerLars Wirzenius <liw@liw.fi>2022-05-06 09:56:18 +0300
commit52ccfa5a1bf2893bdc63ff1bad2b2a88ca86ef95 (patch)
tree2efaf68cf578edac43104591480a0104c17cf8a3 /src/doc.rs
parent185377775aeeba57f91d6b40a8a599e840db1e90 (diff)
downloadsubplot-52ccfa5a1bf2893bdc63ff1bad2b2a88ca86ef95.tar.gz
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
Diffstat (limited to 'src/doc.rs')
-rw-r--r--src/doc.rs4
1 files changed, 2 insertions, 2 deletions
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<Path> + 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<String, SubplotError> {
- let json = serde_json::to_string(&self.ast)?;
+ let json = serde_json::to_string(&self.ast).map_err(SubplotError::AstJson)?;
Ok(json)
}