Skip to content

Commit

Permalink
fix(context): pass on diagnostic metadata when wrapping with Report
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Sep 10, 2021
1 parent 0ba3358 commit e4fdac3
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
48 changes: 47 additions & 1 deletion src/eyreish/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
5 changes: 4 additions & 1 deletion src/eyreish/wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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 {
Expand All @@ -85,4 +89,3 @@ impl Display for BoxedError {
}

impl StdError for BoxedError {}
impl Diagnostic for BoxedError {}

0 comments on commit e4fdac3

Please sign in to comment.