GithubHelp home page GithubHelp logo

Backtrace and Spantrace support about miette HOT 5 OPEN

zkat avatar zkat commented on June 11, 2024
Backtrace and Spantrace support

from miette.

Comments (5)

zkat avatar zkat commented on June 11, 2024 1

miette does have backtrace printing/hook capabilities for panics. What I'm looking for is support for printing backtraces from backtrace fields in errors. From thiserror docs:

image

anyhow then looks for these provided backtraces and prints them. From the anyhow docs:

image

from miette.

erratic-pattern avatar erratic-pattern commented on June 11, 2024

@zkat I've been working on some basic backtrace stuff with miette as a library user, but I could try to adapt it into a proper feature at some point.

backtrace code I pulled directly from human-panic, which is also what eyre uses last I checked: https://github.com/cloudtruth/cloudtruth-cli/blob/8ba6b5a4bfde7684cbeac128f68fa4f4f4366408/crates/integration-test-harness/src/backtrace.rs#L13

And then I created a very basic Diagnostic for panic messages with an optional backtrace: https://github.com/cloudtruth/cloudtruth-cli/blob/8ba6b5a4bfde7684cbeac128f68fa4f4f4366408/crates/integration-test-harness/src/panic.rs#L55

What do you think the best approach is for adding something like this to the library? Something similar to eyre does it where it just checks for RUST_BACKTRACE and RUST_SPANTRACE? Also a fancier backtrace renderer is probably in order.

from miette.

erratic-pattern avatar erratic-pattern commented on June 11, 2024

The use case with backtraces that I built on top of miette is to actually show source code from failing unit tests. To do this I use track_caller to find the source file of the code that installed the panic handler, and then search the backtrace for the first frame matching that directory path. See https://github.com/cloudtruth/cloudtruth-cli/blob/8ba6b5a4bfde7684cbeac128f68fa4f4f4366408/crates/integration-test-harness/src/source_span.rs#L75

The install function is called on each test from a #[use_test_harness] attribute that I wrote.

Output looks like this:
image

Maybe this could be a second crate that someone could choose to pull in if they're specifically wanting better cargo test reports?

from miette.

erratic-pattern avatar erratic-pattern commented on June 11, 2024

Made some improvements on my previous version of panic reporting by using actual Diagnostics sources instead of ad-hoc cause chains. So now there's a root Panic report and then a PanicLocation report on top of it if the panic location is available. See code here

Output example with backtrace:

image

without backtrace:

image

from miette.

zkat avatar zkat commented on June 11, 2024

here's miette's panic hook stuff: https://github.com/zkat/miette/blob/main/src/panic.rs

from miette.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.