Something went wrong. Try again.
forked from zhaofengli/colmena
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647//! Automatic troubleshooter.//!//! Tries to provide some useful hints when things go wrong.
use std::env;use std::future::Future;
use snafu::ErrorCompat;
use crate::error::ColmenaError;
/// Runs a closure and tries to troubleshoot if it returns an error.pub async fn run_wrapped<F, T>(f: F) -> Twhere F: Future<Output = Result<T, ColmenaError>>,{ match f.await { Ok(r) => r, Err(error) => { tracing::error!("-----"); tracing::error!("Operation failed with error: {}", error);
troubleshoot(&error);
// Ensure we exit with a code quit::with_code(1); } }}
fn troubleshoot(error: &ColmenaError) { if let Some(bt) = ErrorCompat::backtrace(error) { if backtrace_enabled() { eprintln!("Backtrace:"); eprint!("{:?}", bt); } else { eprintln!( "Hint: Backtrace available - Use `RUST_BACKTRACE=1` environment variable to display a backtrace" ); } }}
fn backtrace_enabled() -> bool { matches!(env::var("RUST_BACKTRACE"), Ok(backtrace_conf) if backtrace_conf != "0")}