-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use
std::backtrace::Backtrace
as the default backtrace provider
This also bumps our default Rust version to 1.65. Closes #357
- Loading branch information
1 parent
a239d70
commit ae4679e
Showing
26 changed files
with
291 additions
and
453 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
64 changes: 0 additions & 64 deletions
64
compatibility-tests/backtrace-shim/tests/backtrace_delegation.rs
This file was deleted.
Oops, something went wrong.
20 changes: 0 additions & 20 deletions
20
compatibility-tests/backtrace-shim/tests/whatever_nested.rs
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,4 @@ authors = ["Jake Goulding <[email protected]>"] | |
edition = "2018" | ||
|
||
[dependencies] | ||
snafu = { path = "../..", default-features = false, features = ["backtraces"] } | ||
snafu = { path = "../..", default-features = false, features = ["std"] } |
4 changes: 2 additions & 2 deletions
4
...atibility-tests/backtrace-shim/Cargo.toml → compatibility-tests/v1_61/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
[package] | ||
name = "backtrace-shim" | ||
name = "v1_61" | ||
version = "0.1.0" | ||
authors = ["Jake Goulding <[email protected]>"] | ||
edition = "2018" | ||
|
||
[dependencies] | ||
snafu = { path = "../..", features = ["backtraces"] } | ||
snafu = { path = "../..", default-features = false, features = ["std", "rust_1_61"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1.61 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#![cfg(test)] | ||
|
||
use snafu::{prelude::*, Backtrace, ErrorCompat}; | ||
|
||
type AnotherError = Box<dyn std::error::Error>; | ||
|
||
#[derive(Debug, Snafu)] | ||
enum Error { | ||
#[snafu(display("Invalid user {}:\n{}", user_id, backtrace))] | ||
InvalidUser { user_id: i32, backtrace: Backtrace }, | ||
WithSource { | ||
source: AnotherError, | ||
backtrace: Backtrace, | ||
}, | ||
WithSourceAndOtherInfo { | ||
user_id: i32, | ||
source: AnotherError, | ||
backtrace: Backtrace, | ||
}, | ||
} | ||
|
||
type Result<T, E = Error> = std::result::Result<T, E>; | ||
|
||
fn example(user_id: i32) -> Result<()> { | ||
ensure!(user_id >= 42, InvalidUserSnafu { user_id }); | ||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn display_can_access_backtrace() { | ||
let e = example(0).unwrap_err(); | ||
let text = e.to_string(); | ||
assert!( | ||
text.contains("disabled backtrace"), | ||
"{:?} does not contain expected text", | ||
text | ||
); | ||
} | ||
|
||
fn trigger() -> Result<(), AnotherError> { | ||
Err("boom".into()) | ||
} | ||
|
||
#[test] | ||
fn errors_with_sources_can_have_backtraces() { | ||
let e = trigger().context(WithSourceSnafu).unwrap_err(); | ||
let backtrace = ErrorCompat::backtrace(&e).unwrap(); | ||
assert!(backtrace.to_string().contains("disabled backtrace")); | ||
} | ||
|
||
#[test] | ||
fn errors_with_sources_and_other_info_can_have_backtraces() { | ||
let e = trigger() | ||
.context(WithSourceAndOtherInfoSnafu { user_id: 42 }) | ||
.unwrap_err(); | ||
let backtrace = ErrorCompat::backtrace(&e).unwrap(); | ||
assert!(backtrace.to_string().contains("disabled backtrace")); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
pub use backtrace::Backtrace; | ||
|
||
impl crate::GenerateImplicitData for Backtrace { | ||
fn generate() -> Self { | ||
Backtrace::new() | ||
} | ||
} | ||
|
||
impl crate::AsBacktrace for Backtrace { | ||
fn as_backtrace(&self) -> Option<&Backtrace> { | ||
Some(self) | ||
} | ||
} |
File renamed without changes.
Oops, something went wrong.