Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It's technically feasible to add SpanTrace support to thiserror fairly easily (30 mins work - Issue: https://github.com/dtolnay/thiserror/issues/400, PR: https://github.com/dtolnay/thiserror/pull/401). This would solve part of the problem in a way that is meaningfully good for that side of the ecosystem. I suspect you could probably do something similar for Snafu


Without deeply looking into it, I'd expect that to integrate with SNAFU, you could basically write something like this:

    struct SpanTraceWrapper(tracing_error::SpanTrace);
    
    impl snafu::GenerateImplicitData for SpanTraceWrapper {
        fn generate() -> Self {
            Self(tracing_error::SpanTrace::capture())
        }
    }
And then you can use it as

    #[derive(Debug, Snafu)]
    struct SomeError {
        #[snafu(implicit)]
        span_trace: SpanTraceWrapper,
    }
This will capture the `SpanTrace` whenever `SomeError` is constructed (e.g. `thing().context(SomeSnafu)` or `SomeSnafu.fail()`.


Neat :)




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: