Skip to content
This repository was archived by the owner on Aug 16, 2021. It is now read-only.

Commit 01b23d8

Browse files
committed
Backtrace generation is now a feature
Fixes #52.
1 parent 1d00e82 commit 01b23d8

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,8 @@ repository = "https://github.com/brson/error-chain"
1313

1414
license = "MIT OR Apache-2.0"
1515

16+
[features]
17+
default = ["backtrace"]
18+
1619
[dependencies]
17-
backtrace = "0.2.1"
20+
backtrace = {version = "0.2.1", optional = true}

src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,16 +304,23 @@
304304
//! and `chain_err` invocations of compatible types. To read the
305305
//! backtrace just call the `backtrace()` method.
306306
//!
307+
//! Backtrace generation can be disabled by turning off the `backtrace` feature.
308+
//!
307309
//! ## Iteration
308310
//!
309311
//! The `iter` method returns an iterator over the chain of error boxes.
310312
//!
311313
//! [error-type]: https://github.com/DanielKeep/rust-error-type
312314
//! [quick-error]: https://github.com/tailhook/quick-error
313315
316+
#[cfg(feature = "backtrace")]
314317
extern crate backtrace;
315318

319+
#[cfg(feature = "backtrace")]
316320
pub use backtrace::Backtrace;
321+
#[cfg(not(feature = "backtrace"))]
322+
#[derive(Debug)]
323+
pub enum Backtrace {}
317324

318325
mod quick_error;
319326

@@ -689,9 +696,15 @@ impl<'a> Iterator for ErrorChainIter<'a> {
689696
/// Returns a backtrace of the current call stack if `RUST_BACKTRACE`
690697
/// is set to anything but ``0``, and `None` otherwise. This is used
691698
/// in the generated error implementations.
699+
#[cfg(feature = "backtrace")]
692700
pub fn make_backtrace() -> Option<Arc<Backtrace>> {
693701
match std::env::var_os("RUST_BACKTRACE") {
694702
Some(ref val) if val != "0" => Some(Arc::new(Backtrace::new())),
695703
_ => None
696704
}
697705
}
706+
707+
#[cfg(not(feature = "backtrace"))]
708+
pub fn make_backtrace() -> Option<Arc<Backtrace>> {
709+
None
710+
}

tests/tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ fn empty() {
130130
}
131131

132132
#[test]
133+
#[cfg(feature = "backtrace")]
133134
fn has_backtrace_depending_on_env() {
134135
use std::env;
135136

0 commit comments

Comments
 (0)