fix(context): pass on diagnostic metadata when wrapping with `Report`

This commit is contained in:
Kat Marchán 2021-09-09 12:58:58 -07:00
parent 0ba3358443
commit e4fdac38ea
No known key found for this signature in database
GPG Key ID: AEB529C08A3C7E9E
2 changed files with 51 additions and 2 deletions

View File

@ -125,9 +125,55 @@ where
D: Display,
E: Diagnostic + 'static,
{
fn code<'a>(&'a self) -> Option<Box<dyn Display + 'a>> {
self.error.code()
}
fn severity(&self) -> Option<crate::Severity> {
self.error.severity()
}
fn help<'a>(&'a self) -> Option<Box<dyn Display + 'a>> {
self.error.help()
}
fn url<'a>(&'a self) -> Option<Box<dyn Display + 'a>> {
self.error.url()
}
fn snippets<'a>(
&'a self,
) -> Option<Box<dyn Iterator<Item = crate::DiagnosticSnippet<'a>> + 'a>> {
self.error.snippets()
}
}
impl<D> Diagnostic for ContextError<D, Report> where D: Display {}
impl<D> Diagnostic for ContextError<D, Report>
where
D: Display,
{
fn code<'a>(&'a self) -> Option<Box<dyn Display + 'a>> {
self.error.inner.diagnostic().code()
}
fn severity(&self) -> Option<crate::Severity> {
self.error.inner.diagnostic().severity()
}
fn help<'a>(&'a self) -> Option<Box<dyn Display + 'a>> {
self.error.inner.diagnostic().help()
}
fn url<'a>(&'a self) -> Option<Box<dyn Display + 'a>> {
self.error.inner.diagnostic().url()
}
fn snippets<'a>(
&'a self,
) -> Option<Box<dyn Iterator<Item = crate::DiagnosticSnippet<'a>> + 'a>> {
self.error.inner.diagnostic().snippets()
}
}
struct Quoted<D>(D);

View File

@ -4,6 +4,8 @@ use std::error::Error as StdError;
use crate::Diagnostic;
use crate as miette;
#[repr(transparent)]
pub(crate) struct DisplayError<M>(pub(crate) M);
@ -69,7 +71,9 @@ impl Display for NoneError {
impl StdError for NoneError {}
impl Diagnostic for NoneError {}
#[derive(miette_derive::Diagnostic)]
#[repr(transparent)]
#[diagnostic(transparent)]
pub(crate) struct BoxedError(pub(crate) Box<dyn Diagnostic + Send + Sync>);
impl Debug for BoxedError {
@ -85,4 +89,3 @@ impl Display for BoxedError {
}
impl StdError for BoxedError {}
impl Diagnostic for BoxedError {}