From 2649fd27c47893dc3ba2445a9932600d1b3d3e63 Mon Sep 17 00:00:00 2001 From: Paul Colomiets Date: Tue, 18 Jan 2022 03:16:08 +0200 Subject: [PATCH] feat(Report): adds `.context()` method to the `Report` (#109) Techically there was a hidden undocumented `context` method. But it was just copied from the `eyre` and there is no evidence that it was used by any user in miette (the method was an alias for `.handler()`). Fixes #108 --- src/eyreish/error.rs | 20 ++++++++----------- ...ntext_access.rs => test_handler_access.rs} | 4 ++-- 2 files changed, 10 insertions(+), 14 deletions(-) rename tests/{test_context_access.rs => test_handler_access.rs} (64%) diff --git a/src/eyreish/error.rs b/src/eyreish/error.rs index f9dc525..b078e5f 100644 --- a/src/eyreish/error.rs +++ b/src/eyreish/error.rs @@ -220,6 +220,14 @@ impl Report { unsafe { Report::construct(error, vtable, handler) } } + /// Compatibility re-export of wrap_err for interop with `anyhow` + pub fn context(self, msg: D) -> Self + where + D: Display + Send + Sync + 'static, + { + self.wrap_err(msg) + } + /// An iterator of the chain of source errors contained by this Report. /// /// This iterator will visit every error in the cause chain of this error @@ -378,18 +386,6 @@ impl Report { pub fn handler_mut(&mut self) -> &mut dyn ReportHandler { self.inner.handler.as_mut().unwrap().as_mut() } - - /// Get a reference to the Handler for this Report. - #[doc(hidden)] - pub fn context(&self) -> &dyn ReportHandler { - self.inner.handler.as_ref().unwrap().as_ref() - } - - /// Get a mutable reference to the Handler for this Report. - #[doc(hidden)] - pub fn context_mut(&mut self) -> &mut dyn ReportHandler { - self.inner.handler.as_mut().unwrap().as_mut() - } } impl From for Report diff --git a/tests/test_context_access.rs b/tests/test_handler_access.rs similarity index 64% rename from tests/test_context_access.rs rename to tests/test_handler_access.rs index 804fbc4..1380ccf 100644 --- a/tests/test_context_access.rs +++ b/tests/test_handler_access.rs @@ -1,7 +1,7 @@ #[test] -fn test_context() { +fn test_handler() { use miette::{miette, Report}; let error: Report = miette!("oh no!"); - let _ = error.context(); + let _ = error.handler(); }