Skip to content

Commit

Permalink
Put backtrace behind a feature
Browse files Browse the repository at this point in the history
  • Loading branch information
leighmcculloch committed Sep 17, 2024
1 parent 4558728 commit 28fec5d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
1 change: 1 addition & 0 deletions soroban-env-host/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ features = ["arbitrary"]

[features]
testutils = ["soroban-env-common/testutils", "recording_mode", "dep:backtrace"]
backtrace = ["dep:backtrace"]
next = ["soroban-env-common/next", "stellar-xdr/next"]
tracy = ["dep:tracy-client", "soroban-env-common/tracy"]
recording_mode = []
Expand Down
15 changes: 9 additions & 6 deletions soroban-env-host/src/host/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
ConversionError, EnvBase, Error, Host, TryFromVal, U32Val, Val,
};

#[cfg(any(test, feature = "testutils"))]
#[cfg(any(test, all(feature = "testutils", feature = "backtrace")))]
use backtrace::{Backtrace, BacktraceFrame};
use core::fmt::Debug;
use std::{
Expand All @@ -18,7 +18,7 @@ use super::metered_clone::MeteredClone;
#[derive(Clone)]
pub(crate) struct DebugInfo {
events: Events,
#[cfg(any(test, feature = "testutils"))]
#[cfg(any(test, all(feature = "testutils", feature = "backtrace")))]
backtrace: Backtrace,
}

Expand Down Expand Up @@ -67,12 +67,12 @@ impl DebugInfo {
Ok(())
}

#[cfg(not(any(test, feature = "testutils")))]
#[cfg(not(any(test, all(feature = "testutils", feature = "backtrace"))))]
fn write_backtrace(&self, _f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
Ok(())
}

#[cfg(any(test, feature = "testutils"))]
#[cfg(any(test, all(feature = "testutils", feature = "backtrace")))]
fn write_backtrace(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
// We do a little trimming here, skipping the first two frames (which
// are always into, from, and one or more Host::err_foo calls) and all
Expand Down Expand Up @@ -296,8 +296,11 @@ impl Host {
self.with_debug_mode(|| {
if let Ok(events_ref) = self.0.events.try_borrow() {
let events = events_ref.externalize(self)?;
let backtrace = Backtrace::new_unresolved();
res = Some(Box::new(DebugInfo { backtrace, events }));
res = Some(Box::new(DebugInfo {
#[cfg(any(test, all(feature = "testutils", feature = "backtrace")))]
backtrace: Backtrace::new_unresolved(),
events,
}));
}
Ok(())
});
Expand Down

0 comments on commit 28fec5d

Please sign in to comment.