From e4fdac38ea8c295468ed0fce563a2df29241986a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kat=20March=C3=A1n?= Date: Thu, 9 Sep 2021 12:58:58 -0700 Subject: [PATCH] fix(context): pass on diagnostic metadata when wrapping with `Report` --- src/eyreish/context.rs | 48 +++++++++++++++++++++++++++++++++++++++++- src/eyreish/wrapper.rs | 5 ++++- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/src/eyreish/context.rs b/src/eyreish/context.rs index a4ae4e93..4d16fc39 100644 --- a/src/eyreish/context.rs +++ b/src/eyreish/context.rs @@ -125,9 +125,55 @@ where D: Display, E: Diagnostic + 'static, { + fn code<'a>(&'a self) -> Option> { + self.error.code() + } + + fn severity(&self) -> Option { + self.error.severity() + } + + fn help<'a>(&'a self) -> Option> { + self.error.help() + } + + fn url<'a>(&'a self) -> Option> { + self.error.url() + } + + fn snippets<'a>( + &'a self, + ) -> Option> + 'a>> { + self.error.snippets() + } } -impl Diagnostic for ContextError where D: Display {} +impl Diagnostic for ContextError +where + D: Display, +{ + fn code<'a>(&'a self) -> Option> { + self.error.inner.diagnostic().code() + } + + fn severity(&self) -> Option { + self.error.inner.diagnostic().severity() + } + + fn help<'a>(&'a self) -> Option> { + self.error.inner.diagnostic().help() + } + + fn url<'a>(&'a self) -> Option> { + self.error.inner.diagnostic().url() + } + + fn snippets<'a>( + &'a self, + ) -> Option> + 'a>> { + self.error.inner.diagnostic().snippets() + } +} struct Quoted(D); diff --git a/src/eyreish/wrapper.rs b/src/eyreish/wrapper.rs index 90e58c17..3104dade 100644 --- a/src/eyreish/wrapper.rs +++ b/src/eyreish/wrapper.rs @@ -4,6 +4,8 @@ use std::error::Error as StdError; use crate::Diagnostic; +use crate as miette; + #[repr(transparent)] pub(crate) struct DisplayError(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); impl Debug for BoxedError { @@ -85,4 +89,3 @@ impl Display for BoxedError { } impl StdError for BoxedError {} -impl Diagnostic for BoxedError {}