Crate facet_miette

Crate facet_miette 

Source
Expand description

§facet-miette

Derive miette::Diagnostic for your error types using facet’s plugin system.

§Usage

Since the crate is named facet-miette but the derive is Diagnostic, you need to use the explicit path syntax:

use facet::Facet;
use facet_miette as diagnostic; // for attribute namespace
use miette::SourceSpan;

#[derive(Facet, Debug)]
#[facet(derive(Error, facet_miette::Diagnostic))]
pub enum ParseError {
    /// Unexpected token in input
    #[facet(diagnostic::code = "parse::unexpected_token")]
    #[facet(diagnostic::help = "Check for typos or missing delimiters")]
    UnexpectedToken {
        #[facet(diagnostic::source_code)]
        src: String,
        #[facet(diagnostic::label = "this token was unexpected")]
        span: SourceSpan,
    },

    /// End of file reached unexpectedly
    #[facet(diagnostic::code = "parse::unexpected_eof")]
    UnexpectedEof,
}

§Attributes

§Container/Variant Level

  • #[facet(diagnostic::code = "my_lib::error_code")] - Error code for this diagnostic
  • #[facet(diagnostic::help = "Helpful message")] - Help text shown to user
  • #[facet(diagnostic::url = "https://...")] - URL for more information
  • #[facet(diagnostic::severity = "warning")] - Severity: “error”, “warning”, or “advice”

§Field Level

  • #[facet(diagnostic::source_code)] - Field containing the source text (impl SourceCode)
  • #[facet(diagnostic::label = "description")] - Field is a span to highlight with label
  • #[facet(diagnostic::related)] - Field contains related diagnostics (iterator)

§Integration with facet-error

You’ll typically use both Error and Diagnostic together:

#[derive(Facet, Debug)]
#[facet(derive(Error, facet_miette::Diagnostic))]
pub enum MyError {
    /// Something went wrong
    #[facet(diagnostic::code = "my_error")]
    SomeError,
}

Macros§

__facet_invoke
Plugin chain entry point.

Structs§

LabeledSpan
A labeled SourceSpan.
SourceSpan
Span within a SourceCode

Enums§

Attr
Diagnostic attribute types for configuring miette::Diagnostic implementation.
Severity
Diagnostic severity. Intended to be used by ReportHandlers to change the way different Diagnostics are displayed. Defaults to Severity::Error.

Traits§

Diagnostic
Adds rich metadata to your Error that can be used by Report to print really nice and human-friendly error messages.
SourceCode
Represents readable source code of some sort.