Skip to main content

default/
default.rs

1//! Previews the default (plain-text) error output.
2//!
3//! Run with:
4//!
5//! ```sh
6//! cargo run --example default
7//! ```
8
9fn main() {
10    let err = build_error();
11
12    // The `Display` implementation (and `Error::message`) produces the
13    // default, human-readable representation of the error.
14    println!("{err}");
15}
16
17/// Builds a representative, multi-layered error for demonstration purposes.
18fn build_error() -> human_errors::Error {
19    human_errors::wrap_user(
20        human_errors::wrap_system(
21            std::io::Error::new(
22                std::io::ErrorKind::PermissionDenied,
23                "os error 13: permission denied",
24            ),
25            "Failed to read the configuration file at /etc/demo/config.yml.",
26            &["Ensure the application has permission to read the file."],
27        ),
28        "We could not load your configuration.",
29        &["Check that the --config option points to a readable file."],
30    )
31}