exit_code/
exit_code.rs

1//! Example of using `attach` to set a custom exit code. Requires nightly and std feature.
2
3use core::error::Error;
4use std::process::{ExitCode, Termination as _};
5
6use error_stack::Report;
7
8#[derive(Debug)]
9struct CustomError;
10
11impl Error for CustomError {}
12
13impl core::fmt::Display for CustomError {
14    fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
15        fmt.write_str("Custom Error")
16    }
17}
18
19fn main() -> ExitCode {
20    let report = Report::new(CustomError)
21        .attach_opaque(ExitCode::from(100))
22        .attach("this error has an exit code of 100!");
23
24    report.report()
25}