anystack 0.6.0-alpha.3

Flexible and comprehensive error handling.
Documentation
#![cfg(feature = "spantrace")]

mod common;

use anystack::Report;
use common::*;
use tracing_error::{ErrorLayer, SpanTrace};
use tracing_subscriber::layer::SubscriberExt as _;

fn install_tracing_subscriber() {
    static ONCE: std::sync::Once = std::sync::Once::new();
    ONCE.call_once(|| {
        tracing::subscriber::set_global_default(
            tracing_subscriber::Registry::default().with(ErrorLayer::default()),
        )
        .expect("Could not set tracing subscriber");
    });
}

#[test]
fn captured() {
    #[tracing::instrument]
    fn func_b() -> Result<(), Report<RootError>> {
        create_error()
    }

    #[tracing::instrument]
    fn func_a() -> Result<(), Report<RootError>> {
        func_b()
    }

    install_tracing_subscriber();

    let report = capture_error(func_a);

    let span_trace = report
        .downcast_ref::<SpanTrace>()
        .expect("No span trace captured");

    let mut num_spans = 0;
    span_trace.with_spans(|_, _| {
        num_spans += 1;
        true
    });
    assert_eq!(num_spans, 2);
}