use core::{error::Error, fmt};
use std::io;
use ts_error_stack::Report;
fn main() -> Result<(), Report<MainError>> {
Err(MainError::ReadConfigFile {
source: ReadConfigFileError(io::Error::new(
io::ErrorKind::NotFound,
"the file `some-fake-file` could not be found",
)),
}
.into())
}
#[derive(Debug)]
enum MainError {
ReadConfigFile {
source: ReadConfigFileError,
},
}
impl fmt::Display for MainError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "main_exit encountered an error")
}
}
impl Error for MainError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
match &self {
Self::ReadConfigFile { source, .. } => Some(source),
}
}
}
#[derive(Debug)]
struct ReadConfigFileError(io::Error);
impl fmt::Display for ReadConfigFileError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "the config file could not be read")
}
}
impl Error for ReadConfigFileError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
Some(&self.0)
}
}