2023-07-28 16:21:22 +02:00
|
|
|
use chainerror::Context as _;
|
2018-12-21 13:50:08 +01:00
|
|
|
|
2018-12-20 10:08:54 +01:00
|
|
|
use std::error::Error;
|
2018-12-21 13:50:08 +01:00
|
|
|
use std::io;
|
2018-12-20 10:08:54 +01:00
|
|
|
|
2020-03-03 14:37:11 +01:00
|
|
|
fn do_some_io() -> Result<(), Box<dyn Error + Send + Sync>> {
|
2018-12-21 13:50:08 +01:00
|
|
|
Err(io::Error::from(io::ErrorKind::NotFound))?;
|
2018-12-20 10:08:54 +01:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2020-03-03 14:37:11 +01:00
|
|
|
fn func2() -> Result<(), Box<dyn Error + Send + Sync>> {
|
2020-09-01 21:03:01 +02:00
|
|
|
do_some_io().context("func2 error")?;
|
2018-12-20 10:08:54 +01:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2020-03-03 14:37:11 +01:00
|
|
|
fn func1() -> Result<(), Box<dyn Error + Send + Sync>> {
|
2020-09-01 21:03:01 +02:00
|
|
|
func2().context("func1 error")?;
|
2018-12-20 10:08:54 +01:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2020-03-03 14:37:11 +01:00
|
|
|
fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
|
2018-12-20 10:08:54 +01:00
|
|
|
if let Err(e) = func1() {
|
|
|
|
eprintln!("{:?}", e);
|
2020-09-01 21:03:01 +02:00
|
|
|
std::process::exit(1);
|
2018-12-20 10:08:54 +01:00
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|