pub use std::borrow::Cow;
pub use std::cell::{RefCell, RefMut};
pub use std::cmp::{min, max};
+pub use std::env;
pub use std::fs;
pub use std::fmt::{self, Debug, Display, Write as _};
pub use std::future::Future;
pub use ipnet::IpNet;
pub use itertools::{iproduct, Itertools};
pub use lazy_regex::{regex_captures, regex_is_match, regex_replace_all};
+pub use lazy_static::lazy_static;
pub use log::{trace, debug, info, warn, error};
pub use structopt::StructOpt;
pub use thiserror::Error;
#[derive(Debug)]
struct EyreDedupHandler {
- backtrace: Arc<parking_lot::Mutex<Backtrace>>,
+ backtrace: Option<Arc<parking_lot::Mutex<Backtrace>>>,
}
type EyreDynError<'r> = &'r (dyn std::error::Error + 'static);
}
}
- let mut backtrace = self.backtrace.lock();
- backtrace.resolve();
- write!(f, "\n\nStack backtrace:\n{:?}", backtrace)?;
+ if let Some(bt) = &self.backtrace {
+ let mut bt = bt.lock();
+ bt.resolve();
+ write!(f, "\n\nStack backtrace:\n{:?}", bt)?;
+ }
}
}
#[throws(AE)]
pub fn dedup_eyre_setup() {
eyre::set_hook(Box::new(|_error| {
- let backtrace = Backtrace::new_unresolved();
- let backtrace = Arc::new(backtrace.into());
+ lazy_static! {
+ static ref BACKTRACE: bool = {
+ match env::var("RUST_BACKTRACE") {
+ Ok(s) if s.starts_with("1") => true,
+ Ok(s) if s == "0" => false,
+ Err(env::VarError::NotPresent) => false,
+ x => {
+ eprintln!("warning: RUST_BACKTRACE not understood: {:?}", x);
+ false
+ },
+ }
+ };
+ }
+ let backtrace = if *BACKTRACE {
+ let bt = Backtrace::new_unresolved();
+ let bt = Arc::new(bt.into());
+ Some(bt)
+ } else {
+ None
+ };
Box::new(EyreDedupHandler { backtrace })
}))
.context("set error handler")?;