mirror of
https://github.com/eyre-rs/eyre.git
synced 2025-09-28 13:31:29 +00:00
Merge branch 'master' into fix-nightly-backtraces
This commit is contained in:
commit
87ee15eec8
3
.github/workflows/ci.yml
vendored
3
.github/workflows/ci.yml
vendored
@ -135,8 +135,7 @@ jobs:
|
||||
- uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: clippy
|
||||
args: --all-targets --all-features -- -D warnings
|
||||
|
||||
args: --all-targets --all-features -- -D clippy::style -D clippy::suspicious -D clippy::complexity
|
||||
miri:
|
||||
name: Miri
|
||||
runs-on: ubuntu-latest
|
||||
|
@ -11,39 +11,6 @@ use std::env;
|
||||
use std::fmt::Write as _;
|
||||
use std::{fmt, path::PathBuf, sync::Arc};
|
||||
|
||||
#[derive(Debug)]
|
||||
struct InstallError;
|
||||
|
||||
impl fmt::Display for InstallError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.write_str("could not install the BacktracePrinter as another was already installed")
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for InstallError {}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct InstallThemeError;
|
||||
|
||||
impl fmt::Display for InstallThemeError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.write_str("could not set the provided `Theme` globally as another was already set")
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for InstallThemeError {}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct InstallColorSpantraceThemeError;
|
||||
|
||||
impl fmt::Display for InstallColorSpantraceThemeError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.write_str("could not set the provided `Theme` via `color_spantrace::set_theme` globally as another was already set")
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for InstallColorSpantraceThemeError {}
|
||||
|
||||
/// A struct that represents a theme that is used by `color_eyre`
|
||||
#[derive(Debug, Copy, Clone, Default)]
|
||||
pub struct Theme {
|
||||
|
@ -28,11 +28,13 @@ impl<W> WriterExt for W {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "issue-url")]
|
||||
pub(crate) trait DisplayExt: Sized + Display {
|
||||
fn with_header<H: Display>(self, header: H) -> Header<Self, H>;
|
||||
fn with_footer<F: Display>(self, footer: F) -> Footer<Self, F>;
|
||||
}
|
||||
|
||||
#[cfg(feature = "issue-url")]
|
||||
impl<T> DisplayExt for T
|
||||
where
|
||||
T: Display,
|
||||
@ -80,11 +82,13 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "issue-url")]
|
||||
pub(crate) struct FooterWriter<W> {
|
||||
inner: W,
|
||||
had_output: bool,
|
||||
}
|
||||
|
||||
#[cfg(feature = "issue-url")]
|
||||
impl<W> fmt::Write for FooterWriter<W>
|
||||
where
|
||||
W: fmt::Write,
|
||||
@ -98,6 +102,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "issue-url")]
|
||||
#[allow(explicit_outlives_requirements)]
|
||||
pub(crate) struct Footer<B, H>
|
||||
where
|
||||
@ -108,6 +113,7 @@ where
|
||||
footer: H,
|
||||
}
|
||||
|
||||
#[cfg(feature = "issue-url")]
|
||||
impl<B, H> fmt::Display for Footer<B, H>
|
||||
where
|
||||
B: Display,
|
||||
@ -129,6 +135,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "issue-url")]
|
||||
#[allow(explicit_outlives_requirements)]
|
||||
pub(crate) struct Header<B, H>
|
||||
where
|
||||
@ -139,6 +146,7 @@ where
|
||||
h: H,
|
||||
}
|
||||
|
||||
#[cfg(feature = "issue-url")]
|
||||
impl<B, H> fmt::Display for Header<B, H>
|
||||
where
|
||||
B: Display,
|
||||
|
@ -170,7 +170,12 @@ fn test_backwards_compatibility(target: String, file_name: &str) {
|
||||
fn normalize_backtrace(input: &str) -> String {
|
||||
input
|
||||
.lines()
|
||||
.take_while(|v| !v.contains("core::panic") && !v.contains("theme_test_helper::main"))
|
||||
.take_while(|v| {
|
||||
!v.contains("core::panic")
|
||||
&& !v.contains("theme_test_helper::main")
|
||||
&& !v.contains("theme::test_error_backwards_compatibility::closure")
|
||||
&& !v.contains("theme::test_error_backwards_compatibility::{{closure}}")
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n")
|
||||
}
|
||||
|
@ -58,42 +58,34 @@ where
|
||||
Err(e) => Err(e.ext_report(msg())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "anyhow")]
|
||||
fn context<D>(self, msg: D) -> Result<T, Report>
|
||||
#[cfg(feature = "anyhow")]
|
||||
impl<T, E> crate::ContextCompat<T> for Result<T, E>
|
||||
where
|
||||
Self: WrapErr<T, E>,
|
||||
{
|
||||
#[track_caller]
|
||||
fn context<D>(self, msg: D) -> crate::Result<T, Report>
|
||||
where
|
||||
D: Display + Send + Sync + 'static,
|
||||
{
|
||||
self.wrap_err(msg)
|
||||
}
|
||||
|
||||
#[cfg(feature = "anyhow")]
|
||||
fn with_context<D, F>(self, msg: F) -> Result<T, Report>
|
||||
#[track_caller]
|
||||
fn with_context<D, F>(self, f: F) -> crate::Result<T, Report>
|
||||
where
|
||||
D: Display + Send + Sync + 'static,
|
||||
F: FnOnce() -> D,
|
||||
{
|
||||
self.wrap_err_with(msg)
|
||||
self.wrap_err_with(f)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "anyhow")]
|
||||
impl<T> crate::ContextCompat<T> for Option<T> {
|
||||
fn wrap_err<D>(self, msg: D) -> Result<T, Report>
|
||||
where
|
||||
D: Display + Send + Sync + 'static,
|
||||
{
|
||||
self.context(msg)
|
||||
}
|
||||
|
||||
fn wrap_err_with<D, F>(self, msg: F) -> Result<T, Report>
|
||||
where
|
||||
D: Display + Send + Sync + 'static,
|
||||
F: FnOnce() -> D,
|
||||
{
|
||||
self.with_context(msg)
|
||||
}
|
||||
|
||||
#[track_caller]
|
||||
fn context<D>(self, msg: D) -> Result<T, Report>
|
||||
where
|
||||
D: Display + Send + Sync + 'static,
|
||||
@ -104,6 +96,7 @@ impl<T> crate::ContextCompat<T> for Option<T> {
|
||||
}
|
||||
}
|
||||
|
||||
#[track_caller]
|
||||
fn with_context<D, F>(self, msg: F) -> Result<T, Report>
|
||||
where
|
||||
D: Display + Send + Sync + 'static,
|
||||
|
@ -624,7 +624,7 @@ fn capture_handler(error: &(dyn StdError + 'static)) -> Box<dyn EyreHandler> {
|
||||
}
|
||||
|
||||
impl dyn EyreHandler {
|
||||
/// Returns true if the handler is of the specified type
|
||||
/// Check if the handler is of type `T`
|
||||
pub fn is<T: EyreHandler>(&self) -> bool {
|
||||
// Get `TypeId` of the type this function is instantiated with.
|
||||
let t = core::any::TypeId::of::<T>();
|
||||
@ -1130,21 +1130,6 @@ pub trait WrapErr<T, E>: context::private::Sealed {
|
||||
where
|
||||
D: Display + Send + Sync + 'static,
|
||||
F: FnOnce() -> D;
|
||||
|
||||
/// Compatibility re-export of wrap_err for interop with `anyhow`
|
||||
#[cfg(feature = "anyhow")]
|
||||
#[cfg_attr(track_caller, track_caller)]
|
||||
fn context<D>(self, msg: D) -> Result<T, Report>
|
||||
where
|
||||
D: Display + Send + Sync + 'static;
|
||||
|
||||
/// Compatibility re-export of wrap_err_with for interop with `anyhow`
|
||||
#[cfg(feature = "anyhow")]
|
||||
#[cfg_attr(track_caller, track_caller)]
|
||||
fn with_context<D, F>(self, f: F) -> Result<T, Report>
|
||||
where
|
||||
D: Display + Send + Sync + 'static,
|
||||
F: FnOnce() -> D;
|
||||
}
|
||||
|
||||
/// Provides the [`ok_or_eyre`][OptionExt::ok_or_eyre] method for [`Option`].
|
||||
@ -1202,7 +1187,8 @@ pub trait OptionExt<T>: context::private::Sealed {
|
||||
M: Debug + Display + Send + Sync + 'static;
|
||||
}
|
||||
|
||||
/// Provides the `context` method for `Option` when porting from `anyhow`
|
||||
/// Provides the `context` and `with_context` methods for `Result` and `Option` to enhance
|
||||
/// compatibility when porting from anyhow.
|
||||
///
|
||||
/// This trait is sealed and cannot be implemented for types outside of
|
||||
/// `eyre`.
|
||||
@ -1261,19 +1247,6 @@ pub trait ContextCompat<T>: context::private::Sealed {
|
||||
where
|
||||
D: Display + Send + Sync + 'static,
|
||||
F: FnOnce() -> D;
|
||||
|
||||
/// Compatibility re-export of `context` for porting from `anyhow` to `eyre`
|
||||
#[cfg_attr(track_caller, track_caller)]
|
||||
fn wrap_err<D>(self, msg: D) -> Result<T, Report>
|
||||
where
|
||||
D: Display + Send + Sync + 'static;
|
||||
|
||||
/// Compatibility re-export of `with_context` for porting from `anyhow` to `eyre`
|
||||
#[cfg_attr(track_caller, track_caller)]
|
||||
fn wrap_err_with<D, F>(self, f: F) -> Result<T, Report>
|
||||
where
|
||||
D: Display + Send + Sync + 'static,
|
||||
F: FnOnce() -> D;
|
||||
}
|
||||
|
||||
/// Equivalent to `Ok::<_, eyre::Error>(value)`.
|
||||
|
@ -105,7 +105,7 @@ fn test_context() {
|
||||
Box::new(LocationHandler::new(expected_location))
|
||||
}));
|
||||
|
||||
use eyre::WrapErr;
|
||||
use eyre::ContextCompat;
|
||||
let err = read_path("totally_fake_path")
|
||||
.context("oopsie")
|
||||
.unwrap_err();
|
||||
@ -122,7 +122,7 @@ fn test_with_context() {
|
||||
Box::new(LocationHandler::new(expected_location))
|
||||
}));
|
||||
|
||||
use eyre::WrapErr;
|
||||
use eyre::ContextCompat;
|
||||
let err = read_path("totally_fake_path")
|
||||
.with_context(|| "oopsie")
|
||||
.unwrap_err();
|
||||
@ -131,36 +131,6 @@ fn test_with_context() {
|
||||
println!("{:?}", err);
|
||||
}
|
||||
|
||||
#[cfg(feature = "anyhow")]
|
||||
#[test]
|
||||
fn test_option_compat_wrap_err() {
|
||||
let _ = eyre::set_hook(Box::new(|_e| {
|
||||
let expected_location = file!();
|
||||
Box::new(LocationHandler::new(expected_location))
|
||||
}));
|
||||
|
||||
use eyre::ContextCompat;
|
||||
let err = None::<()>.wrap_err("oopsie").unwrap_err();
|
||||
|
||||
// should panic if the location isn't in our crate
|
||||
println!("{:?}", err);
|
||||
}
|
||||
|
||||
#[cfg(feature = "anyhow")]
|
||||
#[test]
|
||||
fn test_option_compat_wrap_err_with() {
|
||||
let _ = eyre::set_hook(Box::new(|_e| {
|
||||
let expected_location = file!();
|
||||
Box::new(LocationHandler::new(expected_location))
|
||||
}));
|
||||
|
||||
use eyre::ContextCompat;
|
||||
let err = None::<()>.wrap_err_with(|| "oopsie").unwrap_err();
|
||||
|
||||
// should panic if the location isn't in our crate
|
||||
println!("{:?}", err);
|
||||
}
|
||||
|
||||
#[cfg(feature = "anyhow")]
|
||||
#[test]
|
||||
fn test_option_compat_context() {
|
||||
|
@ -4,7 +4,6 @@ mod drop;
|
||||
use self::common::maybe_install_handler;
|
||||
use self::drop::{DetectDrop, Flag};
|
||||
use eyre::Report;
|
||||
use std::marker::Unpin;
|
||||
use std::mem;
|
||||
|
||||
#[test]
|
||||
|
Loading…
x
Reference in New Issue
Block a user