From 55674747e5e73883676f4a982c84d217a37e6da3 Mon Sep 17 00:00:00 2001 From: hasezoey Date: Mon, 21 Aug 2023 13:01:13 +0200 Subject: [PATCH] feat(main): make use of the new results and backtrace --- src/bin/main.rs | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/bin/main.rs b/src/bin/main.rs index ae7cd2bc..0fbf2dc1 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -75,6 +75,32 @@ struct Args { } fn main() { + let res = actual_main(); + + if let Err(err) = res { + eprintln!("Error:\n{err}"); + #[cfg(feature = "backtrace")] + { + let backtrace = err.backtrace().to_string(); + + if backtrace == "disabled backtrace" { + eprintln!( + "note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace" + ); + } else { + eprintln!("{}", backtrace); + } + } + #[cfg(not(feature = "backtrace"))] + { + eprintln!("backtrace support is disabled, enable feature \"backtrace\""); + } + + std::process::exit(1); + } +} + +fn actual_main() -> anyhow::Result<()> { let args: Args = Args::from_args(); let cols = args.autogenerated_columns.unwrap_or_default(); let mut default_table_options = TableOptions::default() @@ -104,5 +130,7 @@ fn main() { schema_path: args.schema_path.unwrap_or("crate::schema::".to_owned()), model_path: args.model_path.unwrap_or("crate::models::".to_owned()), }, - ); + )?; + + Ok(()) }