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
|
/// Diagnostic severity. This may be used by [DiagnosticReporter]s to change the
|
||||||
/// display format of this diagnostic.
|
/// 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
|
/// Additional help text related to this Diagnostic. Do you have any
|
||||||
/// advice for the poor soul who's just run into this issue?
|
/// 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() {
|
let sev = match diagnostic.severity() {
|
||||||
Severity::Error => "Error",
|
Some(Severity::Error) | None => "Error",
|
||||||
Severity::Warning => "Warning",
|
Some(Severity::Warning) => "Warning",
|
||||||
Severity::Advice => "Advice",
|
Some(Severity::Advice) => "Advice",
|
||||||
};
|
};
|
||||||
write!(f, "{}[{}]: {}", sev, diagnostic.code(), diagnostic)?;
|
write!(f, "{}[{}]: {}", sev, diagnostic.code(), diagnostic)?;
|
||||||
|
|
||||||
|
|
@ -151,9 +151,9 @@ impl DiagnosticReporter for JokeReporter {
|
||||||
}
|
}
|
||||||
|
|
||||||
let sev = match diagnostic.severity() {
|
let sev = match diagnostic.severity() {
|
||||||
Severity::Error => "error",
|
Some(Severity::Error) | None => "error",
|
||||||
Severity::Warning => "warning",
|
Some(Severity::Warning) => "warning",
|
||||||
Severity::Advice => "advice",
|
Some(Severity::Advice) => "advice",
|
||||||
};
|
};
|
||||||
writeln!(
|
writeln!(
|
||||||
f,
|
f,
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
use std::fmt;
|
use std::{fmt, sync::Arc};
|
||||||
|
|
||||||
use miette::{
|
use miette::{
|
||||||
Diagnostic, DiagnosticSnippet, DiagnosticReporter, MietteError, MietteReporter, Severity, SourceSpan,
|
Diagnostic, DiagnosticReporter, DiagnosticSnippet, MietteError, MietteReporter,
|
||||||
|
SourceSpan,
|
||||||
};
|
};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
|
|
@ -22,8 +23,6 @@ impl Diagnostic for MyBad {
|
||||||
&"oops::my::bad"
|
&"oops::my::bad"
|
||||||
}
|
}
|
||||||
|
|
||||||
fn severity(&self) -> Severity {
|
|
||||||
Severity::Error
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn help(&self) -> Option<Box<dyn '_ + Iterator<Item = &'_ str>>> {
|
fn help(&self) -> Option<Box<dyn '_ + Iterator<Item = &'_ str>>> {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue