From bda23f018357a80cfaa96db7cf35511ea2a03c79 Mon Sep 17 00:00:00 2001 From: Michael Bryan Date: Thu, 25 Jan 2018 01:15:29 +0800 Subject: [PATCH] Missing backends are no longer fatal --- src/renderer/mod.rs | 17 +++++++++++++---- tests/alternate_backends.rs | 7 +++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs index 835cd2a3..fb8d40cd 100644 --- a/src/renderer/mod.rs +++ b/src/renderer/mod.rs @@ -16,7 +16,7 @@ pub use self::html_handlebars::HtmlHandlebars; mod html_handlebars; use std::fs; -use std::io::Read; +use std::io::{self, Read}; use std::path::PathBuf; use std::process::{Command, Stdio}; use serde_json; @@ -155,13 +155,22 @@ impl Renderer for CmdRenderer { let _ = fs::create_dir_all(&ctx.destination); - let mut child = self.compose_command()? + let mut child = match self.compose_command()? .stdin(Stdio::piped()) .stdout(Stdio::inherit()) .stderr(Stdio::inherit()) .current_dir(&ctx.destination) - .spawn() - .chain_err(|| "Unable to start the renderer")?; + .spawn() { + Ok(c) => c, + Err(ref e) if e.kind() == io::ErrorKind::NotFound => { + warn!("The command wasn't found, is the \"{}\" backend installed?", self.name); + warn!("\tCommand: {}", self.cmd); + return Ok(()); + } + Err(e) => { + return Err(e).chain_err(|| "Unable to start the backend")?; + } + }; { let mut stdin = child.stdin.take().expect("Child has stdin"); diff --git a/tests/alternate_backends.rs b/tests/alternate_backends.rs index f1bf6207..c45da7a4 100644 --- a/tests/alternate_backends.rs +++ b/tests/alternate_backends.rs @@ -24,6 +24,13 @@ fn failing_alternate_backend() { md.build().unwrap_err(); } +#[test] +fn missing_backends_arent_fatal() { + let (md, _temp) = dummy_book_with_backend("missing", "trduyvbhijnorgevfuhn"); + + assert!(md.build().is_ok()); +} + #[test] fn alternate_backend_with_arguments() { let (md, _temp) = dummy_book_with_backend("arguments", "echo Hello World!");