Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove backtraces on error when running rerun binary #4746

Merged
merged 6 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ emath = "0.24.1"

# All of our direct external dependencies should be found here:
ahash = "0.8"
anyhow = "1.0"
anyhow = { version = "1.0", default-features = false }
arboard = { version = "3.2", default-features = false }
argh = "0.1.12"
array-init = "2.1"
Expand Down
2 changes: 1 addition & 1 deletion crates/re_build_tools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ all-features = true


[dependencies]
anyhow.workspace = true
anyhow = { workspace = true, default-features = true }
cargo_metadata.workspace = true
glob.workspace = true
sha2.workspace = true
Expand Down
11 changes: 9 additions & 2 deletions crates/re_log/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,15 @@ pub fn default_log_filter() -> String {
/// Directs [`log`] calls to stderr.
#[cfg(not(target_arch = "wasm32"))]
pub fn setup_native_logging() {
if std::env::var("RUST_BACKTRACE").is_err() {
// Make sure we always produce backtraces for the (hopefully rare) cases when we crash!
if cfg!(debug_assertions) && std::env::var("RUST_BACKTRACE").is_err() {
// In debug build, default `RUST_BACKTRACE` to `1` if it is not set.
// This ensures sure we produce backtraces if our examples (etc) panics.

// Our own crash handler (`re_crash_handler`) always prints a backtraces
// (currently ignoring `RUST_BACKTRACE`) but we only use that for `rerun-cli`, our main binary.

// `RUST_BACKTRACE` also turns on printing backtraces for `anyhow::Error`s that
// are returned from `main` (i.e. if `main` returns `anyhow::Result`).
std::env::set_var("RUST_BACKTRACE", "1");
}

Expand Down
1 change: 1 addition & 0 deletions crates/rerun-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ web_viewer = ["rerun/web_viewer", "rerun/sdk"]

[dependencies]
re_build_info.workspace = true
re_error.workspace = true
re_log.workspace = true
re_memory.workspace = true
rerun = { workspace = true, features = [
Expand Down
17 changes: 13 additions & 4 deletions crates/rerun-cli/src/bin/rerun.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ static GLOBAL: AccountingAllocator<mimalloc::MiMalloc> =
AccountingAllocator::new(mimalloc::MiMalloc);

#[tokio::main]
async fn main() -> anyhow::Result<std::process::ExitCode> {
async fn main() -> std::process::ExitCode {
re_log::setup_native_logging();

// Name the rayon threads for the benefit of debuggers and profilers:
Expand All @@ -27,7 +27,16 @@ async fn main() -> anyhow::Result<std::process::ExitCode> {
.unwrap();

let build_info = re_build_info::build_info!();
rerun::run(build_info, rerun::CallSource::Cli, std::env::args())
.await
.map(std::process::ExitCode::from)

let result = rerun::run(build_info, rerun::CallSource::Cli, std::env::args()).await;

match result {
Ok(exit_code) => std::process::ExitCode::from(exit_code),
Err(err) => {
// Note: we do not print the backtrace here, because our error messages should be short, readable, and actionable.
// If we instead return an `anyhow::Result` from `main`, then the backtrace will be printed if `RUST_BACKTRACE=1`.
eprintln!("Error: {}", re_error::format(err));
std::process::ExitCode::FAILURE
}
}
}
Loading