feat(miette): you nerd-snipe miette into writing a joke reporter?? jail for mother!!

This commit is contained in:
Kat Marchán 2021-08-03 01:13:12 -07:00
parent a437f44511
commit 3ad7666777
No known key found for this signature in database
GPG Key ID: AEB529C08A3C7E9E
1 changed files with 40 additions and 0 deletions

View File

@ -87,3 +87,43 @@ impl DiagnosticReporter for Reporter {
Ok(())
}
}
pub struct JokeReporter;
impl DiagnosticReporter for JokeReporter {
fn debug(
&self,
diagnostic: &(dyn Diagnostic),
f: &mut core::fmt::Formatter<'_>,
) -> core::fmt::Result {
if f.alternate() {
return core::fmt::Debug::fmt(diagnostic, f);
}
let sev = match diagnostic.severity() {
Severity::Error => "error",
Severity::Warning => "warning",
Severity::Advice => "advice",
};
writeln!(
f,
"me, with {} {}: {}",
sev,
diagnostic,
diagnostic
.help()
.unwrap_or_else(|| &["have you tried not failing?"])
.join(" ")
)?;
writeln!(
f,
"miette, her eyes enormous: you {} miette? you {}? oh! oh! jail for mother! jail for mother for One Thousand Years!!!!",
diagnostic.code(),
diagnostic.details().map(|details| {
details.iter().map(|detail| detail.message.clone()).collect::<Option<Vec<String>>>()
}).flatten().map(|x| x.join(", ")).unwrap_or_else(||"try and cause miette to panic".into())
)?;
Ok(())
}
}