Improve error message when failing to run graphviz stuff

Fixes #682
This commit is contained in:
Max Brunsfeld 2020-07-10 10:12:46 -07:00
parent e9ea8192a3
commit 0bfd47e2e5

View file

@ -1,3 +1,4 @@
use super::error::{Error, Result};
use std::io;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc;
@ -31,12 +32,12 @@ pub struct LogSession();
pub struct LogSession(PathBuf, Option<Child>, Option<ChildStdin>);
#[cfg(windows)]
pub fn log_graphs(_parser: &mut Parser, _path: &str) -> std::io::Result<LogSession> {
pub fn log_graphs(_parser: &mut Parser, _path: &str) -> Result<LogSession> {
Ok(LogSession())
}
#[cfg(unix)]
pub fn log_graphs(parser: &mut Parser, path: &str) -> std::io::Result<LogSession> {
pub fn log_graphs(parser: &mut Parser, path: &str) -> Result<LogSession> {
use std::io::Write;
let mut dot_file = std::fs::File::create(path)?;
@ -46,11 +47,13 @@ pub fn log_graphs(parser: &mut Parser, path: &str) -> std::io::Result<LogSession
.stdin(Stdio::piped())
.stdout(dot_file)
.spawn()
.expect("Failed to run Dot");
.map_err(Error::wrap(|| {
"Failed to run the `dot` command. Check that graphviz is installed."
}))?;
let dot_stdin = dot_process
.stdin
.take()
.expect("Failed to open stdin for Dot");
.ok_or_else(|| Error::new("Failed to open stdin for `dot` process.".to_string()))?;
parser.print_dot_graphs(&dot_stdin);
Ok(LogSession(
PathBuf::from(path),