Skip to content

Commit 9bb7399

Browse files
authored
Show backtrace on error if RUST_BACKTRACE=1 is in the environment (#21)
1 parent a01d0f5 commit 9bb7399

File tree

5 files changed

+60
-4
lines changed

5 files changed

+60
-4
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Unreleased
22

33
* Remove last dependency on external git binary, using libgit2 for all git interactions
4+
* Show backtraces on error if RUST_BACKTRACE=1 is in the environment
45

56
# Version 0.2.0
67

Cargo.lock

+48
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ license = false
1616
eula = false
1717

1818
[dependencies]
19-
anyhow = "1.0.79"
19+
anyhow = { version = "1.0.79", features = ["backtrace"] }
2020
clap = { version = "4.5.1", features = ["derive", "env", "wrap_help"] }
2121
console = "0.15.8"
2222
dialoguer = "0.11.0"

src/main.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,11 @@ fn main() {
7272
// An empty message means don't display any error message
7373
let msg = e.to_string();
7474
if !msg.is_empty() {
75-
println!("Error: {:#}", e);
75+
if env::var("RUST_BACKTRACE").as_deref() == Ok("1") {
76+
println!("Error: {:?}", e);
77+
} else {
78+
println!("Error: {:#}", e);
79+
}
7680
}
7781
std::process::exit(1);
7882
}

tests/basic.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ new
116116
#[test]
117117
fn test_no_commit_in_range() {
118118
let td = assert_fs::TempDir::new().unwrap();
119+
eprintln!("tempdir: {:?}", td.path());
119120
git_init(&td);
120121

121122
git_commits(&["a", "b", "c", "d"], &td);
@@ -145,9 +146,11 @@ fn test_no_commit_in_range() {
145146

146147
let assertion = fixup(&td).args(&["-P", "b"]).assert().failure();
147148
let out = string(assertion.get_output().stdout.clone());
149+
let expected = "No commit contains the pattern";
148150
assert!(
149-
out.contains("No commit contains the pattern"),
150-
"actual: {}",
151+
out.contains(expected),
152+
"expected: {}\nactual: {}",
153+
expected,
151154
out
152155
);
153156

0 commit comments

Comments
 (0)