mirror of https://github.com/zkat/miette.git
feat(protocol: Severity is now optional
This commit is contained in:
parent
56986bbd4c
commit
7920a2315c
|
|
@ -22,7 +22,11 @@ pub trait Diagnostic: std::error::Error {
|
|||
|
||||
/// Diagnostic severity. This may be used by [DiagnosticReporter]s to change the
|
||||
/// display format of this diagnostic.
|
||||
fn severity(&self) -> Severity;
|
||||
///
|
||||
/// If `None`, reporters should treat this as [Severity::Error]
|
||||
fn severity(&self) -> Option<Severity> {
|
||||
None
|
||||
}
|
||||
|
||||
/// Additional help text related to this Diagnostic. Do you have any
|
||||
/// advice for the poor soul who's just run into this issue?
|
||||
|
|
|
|||
|
|
@ -103,9 +103,9 @@ impl DiagnosticReporter for MietteReporter {
|
|||
}
|
||||
|
||||
let sev = match diagnostic.severity() {
|
||||
Severity::Error => "Error",
|
||||
Severity::Warning => "Warning",
|
||||
Severity::Advice => "Advice",
|
||||
Some(Severity::Error) | None => "Error",
|
||||
Some(Severity::Warning) => "Warning",
|
||||
Some(Severity::Advice) => "Advice",
|
||||
};
|
||||
write!(f, "{}[{}]: {}", sev, diagnostic.code(), diagnostic)?;
|
||||
|
||||
|
|
@ -151,9 +151,9 @@ impl DiagnosticReporter for JokeReporter {
|
|||
}
|
||||
|
||||
let sev = match diagnostic.severity() {
|
||||
Severity::Error => "error",
|
||||
Severity::Warning => "warning",
|
||||
Severity::Advice => "advice",
|
||||
Some(Severity::Error) | None => "error",
|
||||
Some(Severity::Warning) => "warning",
|
||||
Some(Severity::Advice) => "advice",
|
||||
};
|
||||
writeln!(
|
||||
f,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
use std::fmt;
|
||||
use std::{fmt, sync::Arc};
|
||||
|
||||
use miette::{
|
||||
Diagnostic, DiagnosticSnippet, DiagnosticReporter, MietteError, MietteReporter, Severity, SourceSpan,
|
||||
Diagnostic, DiagnosticReporter, DiagnosticSnippet, MietteError, MietteReporter,
|
||||
SourceSpan,
|
||||
};
|
||||
use thiserror::Error;
|
||||
|
||||
|
|
@ -22,8 +23,6 @@ impl Diagnostic for MyBad {
|
|||
&"oops::my::bad"
|
||||
}
|
||||
|
||||
fn severity(&self) -> Severity {
|
||||
Severity::Error
|
||||
}
|
||||
|
||||
fn help(&self) -> Option<Box<dyn '_ + Iterator<Item = &'_ str>>> {
|
||||
|
|
|
|||
Loading…
Reference in New Issue