From ddee839d9cc044ee0cfadfa0507f077fcd0df7da Mon Sep 17 00:00:00 2001 From: Behnam Esfahbod Date: Wed, 6 Sep 2017 01:05:27 -0700 Subject: [PATCH] [renderer] Err on bad file names, instead of panic Addressing the review comments. --- build.rs | 2 -- src/lib.rs | 2 -- src/renderer/html_handlebars/hbs_renderer.rs | 7 ++++--- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/build.rs b/build.rs index 845f7b07..261a7f2e 100644 --- a/build.rs +++ b/build.rs @@ -25,8 +25,6 @@ mod execs { } -// TODO: Drop after error_chain is fixed -#[allow(unused_doc_comment)] error_chain!{ foreign_links { Io(std::io::Error); diff --git a/src/lib.rs b/src/lib.rs index f1a0d235..fff77bbd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -100,8 +100,6 @@ pub use book::BookItem; pub use renderer::Renderer; /// The error types used through out this crate. -// TODO: Drop after error_chain is fixed -#[allow(unused_doc_comment)] pub mod errors { error_chain!{ foreign_links { diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs index c267ba66..3946439a 100644 --- a/src/renderer/html_handlebars/hbs_renderer.rs +++ b/src/renderer/html_handlebars/hbs_renderer.rs @@ -66,8 +66,9 @@ impl HtmlHandlebars { let filepath = Path::new(&ch.path).with_extension("html"); let rendered = self.post_process(rendered, &normalize_path(filepath.to_str() - .expect(&format!("Bad file name: {}", filepath.display()))), - ctx.book.get_html_config().get_playpen_config()); + .ok_or(Error::from(format!("Bad file name: {}", filepath.display())))?), + ctx.book.get_html_config().get_playpen_config() + ); // Write to file info!("[*] Creating {:?} ✓", filepath.display()); @@ -458,7 +459,7 @@ fn id_from_content(content: &str) -> String { let mut content = content.to_string(); // Skip any tags or html-encoded stuff - static REPL_SUB: &[&str] = &[ + const REPL_SUB: &[&str] = &[ "", "", "",