pub fn err_full(err: &Error)
Expand description
Report an Error
to stderr, printing a list of causes
The message will consist of a red error:
title, followed by the
Display
impl for the underlying error.
Each subsequent wrapped error will have a plain cause:
title.
Examples
Wrapped error.
use narrate::{report, ErrorWrap, Result};
fn setup_config() -> Result<()> {
...
let user_config = parse_config_file(&path)
.wrap_with(|| format!("invalid config file: `{}`", &path))?;
...
}
fn main() {
...
let res = setup_config().wrap("invalid configuration");
if let Err(ref err) = res {
report::err_full(err);
// error: invalid configuration
// cause: invalid config file: `config.toml`
// cause: missing key: `author`
}
...
}
Wrapped error with a help message.
use std::{fs::File, path::PathBuf};
use narrate::{report, CliError, ErrorWrap, Result};
fn run() -> Result<()> {
let path = PathBuf::from("/nopermission/file.txt");
File::create(&path)
.wrap_with(|| CliError::CreateFile(path))
.add_help("try using a valid file name")?;
Ok(())
}
fn main() {
if let Err(err) = run() {
report::err_full(&err);
// error: cannot create file: "/nopermission.txt"
// cause: permission denied
//
// try using a valid file name
}
}