Add the miette dependency to your Cargo.toml and use the #[derive(Error, Diagnostic)] macro on your error types to generate formatted reports automatically.
[dependencies]
miette = "7"
use miette::{Diagnostic, Report};
use thiserror::Error;
#[derive(Error, Diagnostic, Debug)]
#[error("File not found")]
#[diagnostic(code(my_app::file_not_found))]
struct FileNotFound {
#[help]
help: String,
}
fn main() -> Result<(), Report> {
Err(FileNotFound {
help: "Check the path and try again.".to_string(),
}.into())
}