GithubHelp home page GithubHelp logo

Comments (5)

zkat avatar zkat commented on July 22, 2024

Try eprintln!("{:?}", err.into_diagnostic()), iirc

from miette.

zmitchell avatar zmitchell commented on July 22, 2024

That doesn't seem to do the trick. Just to be concrete, let's say I have this type:

#[derive(Debug, Error, Diagnostic)]
#[error("Invalid manifest")]
#[diagnostic(
    code("manifest::parse"),
    url("http://example.com"),
    help("Please check the documentation for the correct format.")
)]
pub struct InvalidManifest {
    #[source_code]
    pub manifest_contents: String,

    #[label = "here"]
    pub span: SourceSpan,
}

If I construct that manually and try printing it with

let err = InvalidManifest {...};
eprintln!("{:?}", err);

I get the debug representation of the InvalidManifest struct. If I print it as

eprintln!("{}", err);

I only see Invalid manifest.

I can also call read_span manually to verify that the span is picking up the correct location of the error.

from miette.

zkat avatar zkat commented on July 22, 2024

@zmitchell you're not calling .into_diagnostic(). The graphical printer is on Report's Debug impl, so you first need to turn your error into a Report.

from miette.

zmitchell avatar zmitchell commented on July 22, 2024

I see, I guess I was confused why I needed to call into_diagnostic on something that already impls Diagnostic

from miette.

zkat avatar zkat commented on July 22, 2024

Yeah I guess the naming is weird. What it actually does it get you a Report :)

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.