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

Update to the new backtrace API #124

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 1 addition & 1 deletion eyre/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pyo3 = { version = "0.20", optional = true, default-features = false }
futures = { version = "0.3", default-features = false }
rustversion = "1.0"
thiserror = "1.0"
trybuild = { version = "1.0.19", features = ["diff"] }
ui_test = "0.21.0"
backtrace = "0.3.46"
anyhow = "1.0.28"
syn = { version = "2.0", features = ["full"] }
Expand Down
37 changes: 20 additions & 17 deletions eyre/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,38 @@ use std::path::Path;
use std::process::{Command, ExitStatus};
use std::str;

// This code exercises the surface area that we expect of the std Backtrace
// type. If the current toolchain is able to compile it, we go ahead and use
// backtrace in eyre.
// This code exercises the surface area that we expect of the Error generic
// member access API. If the current toolchain is able to compile it, then
// anyhow is able to provide backtrace support.
const BACKTRACE_PROBE: &str = r#"
#![feature(backtrace)]
#![allow(dead_code)]
#![feature(error_generic_member_access)]

use std::backtrace::{Backtrace, BacktraceStatus};
use std::error::Error;
use std::fmt::{self, Display};
use std::backtrace::Backtrace;
use std::error::{self, Error, Request};
use std::fmt::{self, Debug, Display};

#[derive(Debug)]
struct E;
struct MyError(Thing);
struct Thing;

impl Display for E {
impl Debug for MyError {
fn fmt(&self, _formatter: &mut fmt::Formatter) -> fmt::Result {
unimplemented!()
}
}

impl Error for E {
fn backtrace(&self) -> Option<&Backtrace> {
let backtrace = Backtrace::capture();
match backtrace.status() {
BacktraceStatus::Captured | BacktraceStatus::Disabled | _ => {}
}
impl Display for MyError {
fn fmt(&self, _formatter: &mut fmt::Formatter) -> fmt::Result {
unimplemented!()
}
}

impl Error for MyError {
fn provide<'a>(&'a self, request: &mut Request<'a>) {
request.provide_ref(&self.0);
}
}

const _: fn(&dyn Error) -> Option<&Backtrace> = |err| error::request_ref::<Backtrace>(err);
"#;

const TRACK_CALLER_PROBE: &str = r#"
Expand Down
2 changes: 1 addition & 1 deletion eyre/src/backtrace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub(crate) enum Backtrace {}
#[cfg(backtrace)]
macro_rules! backtrace_if_absent {
($err:expr) => {
match $err.backtrace() {
match std::error::request_ref::<std::backtrace::Backtrace>($err as &dyn std::error::Error) {
Some(_) => None,
None => Some(Backtrace::capture()),
}
Expand Down
6 changes: 3 additions & 3 deletions eyre/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{ContextCompat, Report, StdError, WrapErr};
use core::fmt::{self, Debug, Display, Write};

#[cfg(backtrace)]
use std::backtrace::Backtrace;
use std::error::Request;

mod ext {
use super::*;
Expand Down Expand Up @@ -144,8 +144,8 @@ where
E: StdError + 'static,
{
#[cfg(backtrace)]
fn backtrace(&self) -> Option<&Backtrace> {
self.error.backtrace()
fn provide<'a>(&'a self, request: &mut Request<'a>) {
StdError::provide(&self.error, request);
}

fn source(&self) -> Option<&(dyn StdError + 'static)> {
Expand Down
6 changes: 4 additions & 2 deletions eyre/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@
unused_parens,
while_true
)]
#![cfg_attr(backtrace, feature(backtrace))]
#![cfg_attr(backtrace, feature(error_generic_member_access))]
#![cfg_attr(doc_cfg, feature(doc_cfg))]
#![allow(
clippy::needless_doctest_main,
Expand Down Expand Up @@ -789,6 +789,8 @@ impl EyreHandler for DefaultHandler {
f: &mut core::fmt::Formatter<'_>,
) -> core::fmt::Result {
use core::fmt::Write as _;
#[cfg(backtrace)]
use std::error::request_ref;

if f.alternate() {
return core::fmt::Debug::fmt(error, f);
Expand Down Expand Up @@ -824,7 +826,7 @@ impl EyreHandler for DefaultHandler {
let backtrace = self
.backtrace
.as_ref()
.or_else(|| error.backtrace())
.or_else(|| request_ref::<Backtrace>(error))
.expect("backtrace capture failed");
if let BacktraceStatus::Captured = backtrace.status() {
write!(f, "\n\nStack backtrace:\n{}", backtrace)?;
Expand Down
7 changes: 5 additions & 2 deletions eyre/src/wrapper.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use crate::StdError;
use core::fmt::{self, Debug, Display};

#[cfg(backtrace)]
use std::error::Request;

#[repr(transparent)]
pub(crate) struct DisplayError<M>(pub(crate) M);

Expand Down Expand Up @@ -83,8 +86,8 @@ impl Display for BoxedError {

impl StdError for BoxedError {
#[cfg(backtrace)]
fn backtrace(&self) -> Option<&crate::backtrace::Backtrace> {
self.0.backtrace()
fn provide<'a>(&'a self, request: &mut Request<'a>) {
self.0.provide(request);
}

fn source(&self) -> Option<&(dyn StdError + 'static)> {
Expand Down
18 changes: 15 additions & 3 deletions eyre/tests/compiletest.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
#[rustversion::attr(not(nightly), ignore)]
#[cfg_attr(not(backtrace), ignore)]
#[cfg_attr(miri, ignore)]
#[test]
fn ui() {
let t = trybuild::TestCases::new();
t.compile_fail("tests/ui/*.rs");
let mut test_dir = std::path::PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap());
test_dir.push("tests");
test_dir.push("ui");
let rust_backtrace_val = "1";
let mut config = ui_test::Config {
mode: ui_test::Mode::Run { exit_code: 0 },
filter_files: vec!["ui_test".to_owned()],

..ui_test::Config::cargo(test_dir)
};
config.program.args = vec!["run".into()];
config.program.envs = vec![("RUST_BACKTRACE".into(), Some(rust_backtrace_val.into()))];

let _ = ui_test::run_tests(config);
}
117 changes: 117 additions & 0 deletions eyre/tests/test_backtrace.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
mod test_backtrace {
use eyre::{eyre, Report, WrapErr};

#[allow(unused_variables)]
#[allow(dead_code)]
enum FailFrame {
None,
Low,
Med,
High,
}

fn low(frame: FailFrame) -> Result<(), Report> {

Check failure on line 13 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Clippy (stable)

function `low` is never used

Check warning on line 13 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly)

function `low` is never used

Check warning on line 13 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --features pyo3)

function `low` is never used

Check warning on line 13 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --features track-caller)

function `low` is never used

Check warning on line 13 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --features auto-install)

function `low` is never used

Check warning on line 13 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta)

function `low` is never used

Check warning on line 13 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --all-features)

function `low` is never used

Check warning on line 13 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --features auto-install)

function `low` is never used

Check warning on line 13 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --no-default-features)

function `low` is never used

Check warning on line 13 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --all-features)

function `low` is never used

Check warning on line 13 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (ubuntu-latest)

function `low` is never used

Check warning on line 13 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --features track-caller)

function `low` is never used

Check warning on line 13 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Miri

function `low` is never used

Check warning on line 13 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --features pyo3)

function `low` is never used

Check warning on line 13 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --no-default-features)

function `low` is never used

Check warning on line 13 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (macOS-latest)

function `low` is never used

Check warning on line 13 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable)

function `low` is never used

Check warning on line 13 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --all-features)

function `low` is never used

Check warning on line 13 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --features auto-install)

function `low` is never used

Check warning on line 13 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (windows-latest)

function `low` is never used

Check warning on line 13 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --features pyo3)

function `low` is never used

Check warning on line 13 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --no-default-features)

function `low` is never used

Check warning on line 13 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --features track-caller)

function `low` is never used
let e: Report = eyre!("This program's goodness is suspect!");
if let FailFrame::Low = frame {
Err::<(), Report>(e).wrap_err("The low-level code has failed!")
} else {
Ok(())
}
}

fn med(frame: FailFrame) -> Result<(), Report> {

Check failure on line 22 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Clippy (stable)

function `med` is never used

Check warning on line 22 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly)

function `med` is never used

Check warning on line 22 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --features pyo3)

function `med` is never used

Check warning on line 22 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --features track-caller)

function `med` is never used

Check warning on line 22 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --features auto-install)

function `med` is never used

Check warning on line 22 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta)

function `med` is never used

Check warning on line 22 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --all-features)

function `med` is never used

Check warning on line 22 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --features auto-install)

function `med` is never used

Check warning on line 22 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --no-default-features)

function `med` is never used

Check warning on line 22 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --all-features)

function `med` is never used

Check warning on line 22 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (ubuntu-latest)

function `med` is never used

Check warning on line 22 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --features track-caller)

function `med` is never used

Check warning on line 22 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Miri

function `med` is never used

Check warning on line 22 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --features pyo3)

function `med` is never used

Check warning on line 22 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --no-default-features)

function `med` is never used

Check warning on line 22 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (macOS-latest)

function `med` is never used

Check warning on line 22 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable)

function `med` is never used

Check warning on line 22 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --all-features)

function `med` is never used

Check warning on line 22 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --features auto-install)

function `med` is never used

Check warning on line 22 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (windows-latest)

function `med` is never used

Check warning on line 22 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --features pyo3)

function `med` is never used

Check warning on line 22 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --no-default-features)

function `med` is never used

Check warning on line 22 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --features track-caller)

function `med` is never used
let e: Report = eyre!("This program's goodness is suspect!");
if let FailFrame::Med = frame {
Err(e).wrap_err("The low-level code has failed!")
} else {
low(frame)
}
}
fn high(frame: FailFrame) -> Result<(), Report> {

Check failure on line 30 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Clippy (stable)

function `high` is never used

Check warning on line 30 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly)

function `high` is never used

Check warning on line 30 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --features pyo3)

function `high` is never used

Check warning on line 30 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --features track-caller)

function `high` is never used

Check warning on line 30 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --features auto-install)

function `high` is never used

Check warning on line 30 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta)

function `high` is never used

Check warning on line 30 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --all-features)

function `high` is never used

Check warning on line 30 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --features auto-install)

function `high` is never used

Check warning on line 30 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --no-default-features)

function `high` is never used

Check warning on line 30 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --all-features)

function `high` is never used

Check warning on line 30 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (ubuntu-latest)

function `high` is never used

Check warning on line 30 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --features track-caller)

function `high` is never used

Check warning on line 30 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Miri

function `high` is never used

Check warning on line 30 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --features pyo3)

function `high` is never used

Check warning on line 30 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --no-default-features)

function `high` is never used

Check warning on line 30 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (macOS-latest)

function `high` is never used

Check warning on line 30 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable)

function `high` is never used

Check warning on line 30 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --all-features)

function `high` is never used

Check warning on line 30 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --features auto-install)

function `high` is never used

Check warning on line 30 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (windows-latest)

function `high` is never used

Check warning on line 30 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --features pyo3)

function `high` is never used

Check warning on line 30 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --no-default-features)

function `high` is never used

Check warning on line 30 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --features track-caller)

function `high` is never used
let e: Report = eyre!("This program's goodness is suspect!");
if let FailFrame::High = frame {
Err(e).wrap_err("The low-level code has failed!")
} else {
med(frame)
}
}

use std::panic;

static BACKTRACE_SNIPPET_HIGH: &str = "

Check failure on line 41 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Clippy (stable)

static `BACKTRACE_SNIPPET_HIGH` is never used

Check warning on line 41 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly)

static `BACKTRACE_SNIPPET_HIGH` is never used

Check warning on line 41 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --features pyo3)

static `BACKTRACE_SNIPPET_HIGH` is never used

Check warning on line 41 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --features track-caller)

static `BACKTRACE_SNIPPET_HIGH` is never used

Check warning on line 41 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --features auto-install)

static `BACKTRACE_SNIPPET_HIGH` is never used

Check warning on line 41 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta)

static `BACKTRACE_SNIPPET_HIGH` is never used

Check warning on line 41 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --all-features)

static `BACKTRACE_SNIPPET_HIGH` is never used

Check warning on line 41 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --features auto-install)

static `BACKTRACE_SNIPPET_HIGH` is never used

Check warning on line 41 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --no-default-features)

static `BACKTRACE_SNIPPET_HIGH` is never used

Check warning on line 41 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --all-features)

static `BACKTRACE_SNIPPET_HIGH` is never used

Check warning on line 41 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (ubuntu-latest)

static `BACKTRACE_SNIPPET_HIGH` is never used

Check warning on line 41 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --features track-caller)

static `BACKTRACE_SNIPPET_HIGH` is never used

Check warning on line 41 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Miri

static `BACKTRACE_SNIPPET_HIGH` is never used

Check warning on line 41 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --features pyo3)

static `BACKTRACE_SNIPPET_HIGH` is never used

Check warning on line 41 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --no-default-features)

static `BACKTRACE_SNIPPET_HIGH` is never used

Check warning on line 41 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (macOS-latest)

static `BACKTRACE_SNIPPET_HIGH` is never used

Check warning on line 41 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable)

static `BACKTRACE_SNIPPET_HIGH` is never used

Check warning on line 41 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --all-features)

static `BACKTRACE_SNIPPET_HIGH` is never used

Check warning on line 41 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --features auto-install)

static `BACKTRACE_SNIPPET_HIGH` is never used

Check warning on line 41 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (windows-latest)

static `BACKTRACE_SNIPPET_HIGH` is never used

Check warning on line 41 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --features pyo3)

static `BACKTRACE_SNIPPET_HIGH` is never used

Check warning on line 41 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --no-default-features)

static `BACKTRACE_SNIPPET_HIGH` is never used

Check warning on line 41 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --features track-caller)

static `BACKTRACE_SNIPPET_HIGH` is never used
10: test_backtrace::test_backtrace::low
at .\\tests\\test_backtrace.rs:14
11: test_backtrace::test_backtrace::med
at .\\tests\\test_backtrace.rs:27
12: test_backtrace::test_backtrace::high
at .\\tests\\test_backtrace.rs:35
13: test_backtrace::test_backtrace::test_backtrace
";

use std::backtrace::Backtrace;

Check failure on line 51 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Clippy (stable)

unused import: `std::backtrace::Backtrace`

Check warning on line 51 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly)

unused import: `std::backtrace::Backtrace`

Check warning on line 51 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --features pyo3)

unused import: `std::backtrace::Backtrace`

Check warning on line 51 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --features track-caller)

unused import: `std::backtrace::Backtrace`

Check warning on line 51 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --features auto-install)

unused import: `std::backtrace::Backtrace`

Check warning on line 51 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta)

unused import: `std::backtrace::Backtrace`

Check warning on line 51 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --all-features)

unused import: `std::backtrace::Backtrace`

Check warning on line 51 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --features auto-install)

unused import: `std::backtrace::Backtrace`

Check warning on line 51 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --no-default-features)

unused import: `std::backtrace::Backtrace`

Check warning on line 51 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --all-features)

unused import: `std::backtrace::Backtrace`

Check warning on line 51 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (ubuntu-latest)

unused import: `std::backtrace::Backtrace`

Check warning on line 51 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --features track-caller)

unused import: `std::backtrace::Backtrace`

Check warning on line 51 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Miri

unused import: `std::backtrace::Backtrace`

Check warning on line 51 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --features pyo3)

unused import: `std::backtrace::Backtrace`

Check warning on line 51 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --no-default-features)

unused import: `std::backtrace::Backtrace`

Check warning on line 51 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (macOS-latest)

unused import: `std::backtrace::Backtrace`

Check warning on line 51 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable)

unused import: `std::backtrace::Backtrace`

Check warning on line 51 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --all-features)

unused import: `std::backtrace::Backtrace`

Check warning on line 51 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --features auto-install)

unused import: `std::backtrace::Backtrace`

Check warning on line 51 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (windows-latest)

unused import: `std::backtrace::Backtrace`

Check warning on line 51 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --features pyo3)

unused import: `std::backtrace::Backtrace`

Check warning on line 51 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --no-default-features)

unused import: `std::backtrace::Backtrace`

Check warning on line 51 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --features track-caller)

unused import: `std::backtrace::Backtrace`
use std::sync::{Arc, Mutex};

/* This test does produce a backtrace for panic or error with the standard panic hook,
* but I'm at a loss for how to capture the backtrace and compare it to a snippet.
*/
#[cfg_attr(not(backtrace), ignore)]
// #[test]
// #[should_panic]
fn test_backtrace_simple() {

Check failure on line 60 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Clippy (stable)

function `test_backtrace_simple` is never used

Check warning on line 60 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly)

function `test_backtrace_simple` is never used

Check warning on line 60 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --features pyo3)

function `test_backtrace_simple` is never used

Check warning on line 60 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --features track-caller)

function `test_backtrace_simple` is never used

Check warning on line 60 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --features auto-install)

function `test_backtrace_simple` is never used

Check warning on line 60 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta)

function `test_backtrace_simple` is never used

Check warning on line 60 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --all-features)

function `test_backtrace_simple` is never used

Check warning on line 60 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --features auto-install)

function `test_backtrace_simple` is never used

Check warning on line 60 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --no-default-features)

function `test_backtrace_simple` is never used

Check warning on line 60 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --all-features)

function `test_backtrace_simple` is never used

Check warning on line 60 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (ubuntu-latest)

function `test_backtrace_simple` is never used

Check warning on line 60 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --features track-caller)

function `test_backtrace_simple` is never used

Check warning on line 60 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Miri

function `test_backtrace_simple` is never used

Check warning on line 60 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --features pyo3)

function `test_backtrace_simple` is never used

Check warning on line 60 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --no-default-features)

function `test_backtrace_simple` is never used

Check warning on line 60 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (macOS-latest)

function `test_backtrace_simple` is never used

Check warning on line 60 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable)

function `test_backtrace_simple` is never used

Check warning on line 60 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --all-features)

function `test_backtrace_simple` is never used

Check warning on line 60 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --features auto-install)

function `test_backtrace_simple` is never used

Check warning on line 60 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (windows-latest)

function `test_backtrace_simple` is never used

Check warning on line 60 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --features pyo3)

function `test_backtrace_simple` is never used

Check warning on line 60 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --no-default-features)

function `test_backtrace_simple` is never used

Check warning on line 60 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --features track-caller)

function `test_backtrace_simple` is never used
let report = high(FailFrame::Low).expect_err("Must be error");
let handler: &eyre::DefaultHandler = report.handler().downcast_ref().unwrap();
eprintln!("{:?}", handler);
// let backtrace: Backtrace = handler.backtrace.unwrap();
// let
/*
let backtrace: Option<Backtrace> = handler.backtrace;
assert!(backtrace.is_some());
*/
}

#[cfg_attr(not(backtrace), ignore)]
// #[test]
fn test_backtrace() {

Check failure on line 74 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Clippy (stable)

function `test_backtrace` is never used

Check warning on line 74 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly)

function `test_backtrace` is never used

Check warning on line 74 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --features pyo3)

function `test_backtrace` is never used

Check warning on line 74 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --features track-caller)

function `test_backtrace` is never used

Check warning on line 74 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --features auto-install)

function `test_backtrace` is never used

Check warning on line 74 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta)

function `test_backtrace` is never used

Check warning on line 74 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --all-features)

function `test_backtrace` is never used

Check warning on line 74 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --features auto-install)

function `test_backtrace` is never used

Check warning on line 74 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (beta, --no-default-features)

function `test_backtrace` is never used

Check warning on line 74 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --all-features)

function `test_backtrace` is never used

Check warning on line 74 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (ubuntu-latest)

function `test_backtrace` is never used

Check warning on line 74 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --features track-caller)

function `test_backtrace` is never used

Check warning on line 74 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Miri

function `test_backtrace` is never used

Check warning on line 74 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --features pyo3)

function `test_backtrace` is never used

Check warning on line 74 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (nightly, --no-default-features)

function `test_backtrace` is never used

Check warning on line 74 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (macOS-latest)

function `test_backtrace` is never used

Check warning on line 74 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable)

function `test_backtrace` is never used

Check warning on line 74 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --all-features)

function `test_backtrace` is never used

Check warning on line 74 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --features auto-install)

function `test_backtrace` is never used

Check warning on line 74 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (windows-latest)

function `test_backtrace` is never used

Check warning on line 74 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --features pyo3)

function `test_backtrace` is never used

Check warning on line 74 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --no-default-features)

function `test_backtrace` is never used

Check warning on line 74 in eyre/tests/test_backtrace.rs

View workflow job for this annotation

GitHub Actions / Test Suite (stable, --features track-caller)

function `test_backtrace` is never used
/* FIXME: check that the backtrace actually happens here
* It's not trivial to compare the *whole* output,
* but we could somehow grep the output for 'stack_backtrace',
* maybe check for this string... though including line numbers is problematic,
* and the frames could change if core changes.
*
*/

let global_buffer = Arc::new(Mutex::new(String::new()));
let old_hook = panic::take_hook();
panic::set_hook({
/* fixme: this panic hook is not working ;(
*/
let global_buffer = global_buffer.clone();
Box::new(move |info| {
let mut global_buffer = global_buffer.lock().unwrap();

if let Some(s) = info.payload().downcast_ref::<&str>() {
println!("PANIC: {}", *s);
*global_buffer = (*s).to_string()
} else {
// panic!("help!");
}
})
});

panic::catch_unwind(|| {
high(FailFrame::Low).unwrap(); //.unwrap_or(println!("test"));
})
.expect_err("Backtrace test did not panic.");
let binding = global_buffer.lock().unwrap();
let panic_output = binding.clone();
panic::set_hook(old_hook);
if !panic_output.contains(BACKTRACE_SNIPPET_HIGH) {
println!("Backtrace test fail.");
println!("Expected output to contain:");
println!("{}", BACKTRACE_SNIPPET_HIGH);
println!("Instead, outputted:");
println!("{}", panic_output);
panic!();
}
}
}
14 changes: 14 additions & 0 deletions eyre/tests/ui/ui_test_backtrace.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use eyre::Report;

fn fail(fail: bool) -> Result<(), Report> {
let e: Report = eyre!("Internal error message");
if fail {
Err(e).wrap_err("External error message")
} else {
Ok(())
}
}

fn main() {
fail(true);
}
1 change: 1 addition & 0 deletions eyre/tests/ui/ui_test_backtrace.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
error: embedded manifest `$DIR/ui_test_backtrace.rs` requires `-Zscript`
Loading