2020-08-28 16:45:24 +02:00
|
|
|
use chainerror::prelude::v1::*;
|
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
|
|
|
use std::result::Result;
|
|
|
|
|
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>> {
|
2018-12-20 15:14:21 +01:00
|
|
|
let filename = "foo.txt";
|
2020-08-28 16:45:24 +02:00
|
|
|
do_some_io().cherr(format!("Error reading '{}'", filename))?;
|
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-08-28 16:45:24 +02:00
|
|
|
func2().cherr("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);
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|