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 (implSourceCode)#[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§
- Labeled
Span - A labeled
SourceSpan. - Source
Span - Span within a
SourceCode
Enums§
- Attr
- Diagnostic attribute types for configuring miette::Diagnostic implementation.
- Severity
Diagnosticseverity. Intended to be used byReportHandlers to change the way differentDiagnostics are displayed. Defaults toSeverity::Error.
Traits§
- Diagnostic
- Adds rich metadata to your Error that can be used by
Reportto print really nice and human-friendly error messages. - Source
Code - Represents readable source code of some sort.