print error chain

This commit is contained in:
naskya 2024-06-20 02:33:01 +09:00
parent 9c248168b4
commit 5c515f6d87
Signed by: naskya
GPG key ID: 712D413B3A9FED5C

View file

@ -20,7 +20,7 @@ enum Commands {
Config(command::config::Commands),
}
fn main() -> Result<(), command::Error> {
fn run() -> Result<(), command::Error> {
let args = Args::parse();
match args.command {
@ -30,3 +30,22 @@ fn main() -> Result<(), command::Error> {
Ok(())
}
fn main() {
let res = run();
if let Err(err) = res {
println!("An error occurred!");
println!(" raw: {:?}", err);
println!(" message: {}", err);
let mut err: &dyn std::error::Error = &err;
while let Some(src) = err.source() {
println!("caused by: {}", src);
err = src;
}
std::process::exit(1);
}
}