Skip to content

Commit

Permalink
src/main: Print backtrace on failure if requested through RUST_{LIB_}…
Browse files Browse the repository at this point in the history
…BACKTRACE

Signed-off-by: Alberto Faria <[email protected]>
  • Loading branch information
albertofaria committed Apr 23, 2024
1 parent b349ec0 commit ee504a4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ rust-version = "1.74"
license = "GPL-2.0-or-later"

[dependencies.anyhow]
version = "1.0.46"
version = "1.0.77"

[dependencies.camino]
version = "1.1"
Expand Down
8 changes: 8 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ use std::process;
fn main() {
if let Err(e) = crun_vm::main(env::args_os().skip(1)) {
eprintln!("{:#}", e);

let rust_backtrace = env::var_os("RUST_BACKTRACE").unwrap_or_default();
let rust_lib_backtrace = env::var_os("RUST_LIB_BACKTRACE").unwrap_or_default();

if (rust_backtrace == "1" || rust_lib_backtrace == "1") && rust_lib_backtrace != "0" {
eprintln!("\n{}\n", e.backtrace());
}

process::exit(1);
}
}
4 changes: 3 additions & 1 deletion tests/env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ repo_root=$( readlink -e "$( dirname "$0" )/.." )
temp_dir=$( mktemp -d )
trap '__extra_cleanup; rm -fr "$temp_dir"' EXIT

export RUST_BACKTRACE=1 RUST_LIB_BACKTRACE=1

case "${1:-}" in
build)
if (( $# != 1 )); then
Expand Down Expand Up @@ -383,7 +385,7 @@ run)
TEMP_DIR=~/$label.temp
UTIL_DIR=~/$label.util
ENGINE=$engine
export RUST_BACKTRACE=${RUST_BACKTRACE:-1}
export RUST_BACKTRACE=1 RUST_LIB_BACKTRACE=1
$( cat "$t" )\
"

Expand Down

0 comments on commit ee504a4

Please sign in to comment.