Improved error messages using error_chain::ChainedError::display_chain()
This commit is contained in:
parent
1b51cd244e
commit
ebcf41c25b
|
@ -1,17 +1,18 @@
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate clap;
|
extern crate clap;
|
||||||
extern crate env_logger;
|
extern crate env_logger;
|
||||||
|
extern crate error_chain;
|
||||||
extern crate log;
|
extern crate log;
|
||||||
extern crate mdbook;
|
extern crate mdbook;
|
||||||
extern crate open;
|
extern crate open;
|
||||||
|
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
use std::io::{self, Write};
|
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use clap::{App, AppSettings, ArgMatches};
|
use clap::{App, AppSettings, ArgMatches};
|
||||||
use log::{LogLevelFilter, LogRecord};
|
use log::{LogLevelFilter, LogRecord};
|
||||||
use env_logger::LogBuilder;
|
use env_logger::LogBuilder;
|
||||||
|
use error_chain::ChainedError;
|
||||||
|
|
||||||
pub mod build;
|
pub mod build;
|
||||||
pub mod init;
|
pub mod init;
|
||||||
|
@ -59,7 +60,8 @@ fn main() {
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Err(e) = res {
|
if let Err(e) = res {
|
||||||
writeln!(&mut io::stderr(), "An error occured:\n{}", e).ok();
|
eprintln!("{}", e.display_chain());
|
||||||
|
|
||||||
::std::process::exit(101);
|
::std::process::exit(101);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,11 +48,18 @@ impl MDBook {
|
||||||
let config_location = book_root.join("book.toml");
|
let config_location = book_root.join("book.toml");
|
||||||
|
|
||||||
let config = if config_location.exists() {
|
let config = if config_location.exists() {
|
||||||
|
debug!("[*] Loading config from {}", config_location.display());
|
||||||
Config::from_disk(&config_location)?
|
Config::from_disk(&config_location)?
|
||||||
} else {
|
} else {
|
||||||
Config::default()
|
Config::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if log_enabled!(::log::LogLevel::Trace) {
|
||||||
|
for line in format!("Config: {:#?}", config).lines() {
|
||||||
|
trace!("{}", line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
MDBook::load_with_config(book_root, config)
|
MDBook::load_with_config(book_root, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue