From ebcf41c25b9c9e3afa6e95ddc49b2c652a979d3c Mon Sep 17 00:00:00 2001 From: Michael Bryan Date: Mon, 11 Dec 2017 11:42:36 +1100 Subject: [PATCH] Improved error messages using error_chain::ChainedError::display_chain() --- src/bin/mdbook.rs | 6 ++++-- src/book/mod.rs | 7 +++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/bin/mdbook.rs b/src/bin/mdbook.rs index 53de436c..4d7fbd6b 100644 --- a/src/bin/mdbook.rs +++ b/src/bin/mdbook.rs @@ -1,17 +1,18 @@ #[macro_use] extern crate clap; extern crate env_logger; +extern crate error_chain; extern crate log; extern crate mdbook; extern crate open; use std::env; use std::ffi::OsStr; -use std::io::{self, Write}; use std::path::{Path, PathBuf}; use clap::{App, AppSettings, ArgMatches}; use log::{LogLevelFilter, LogRecord}; use env_logger::LogBuilder; +use error_chain::ChainedError; pub mod build; pub mod init; @@ -59,7 +60,8 @@ fn main() { }; if let Err(e) = res { - writeln!(&mut io::stderr(), "An error occured:\n{}", e).ok(); + eprintln!("{}", e.display_chain()); + ::std::process::exit(101); } } diff --git a/src/book/mod.rs b/src/book/mod.rs index 5116e175..941682ee 100644 --- a/src/book/mod.rs +++ b/src/book/mod.rs @@ -48,11 +48,18 @@ impl MDBook { let config_location = book_root.join("book.toml"); let config = if config_location.exists() { + debug!("[*] Loading config from {}", config_location.display()); Config::from_disk(&config_location)? } else { Config::default() }; + if log_enabled!(::log::LogLevel::Trace) { + for line in format!("Config: {:#?}", config).lines() { + trace!("{}", line); + } + } + MDBook::load_with_config(book_root, config) }