feat(protocol: Severity is now optional

This commit is contained in:
Kat Marchán 2021-08-07 22:54:46 -04:00
parent 56986bbd4c
commit 7920a2315c
No known key found for this signature in database
GPG Key ID: AEB529C08A3C7E9E
3 changed files with 14 additions and 11 deletions

View File

@ -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?

View File

@ -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,

View File

@ -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>>> {