Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ rust-version = "1.65.0"

[workspace.dependencies]
indenter = "0.3.0"
once_cell = "1.18.0"
once_cell = { version = "1.18.0", default-features = false }
owo-colors = "4.0"
autocfg = "1.0"

Expand Down
8 changes: 6 additions & 2 deletions eyre/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,18 @@ readme = { workspace = true }
rust-version = { workspace = true }

[features]
default = ["anyhow", "auto-install", "track-caller"]
default = ["anyhow", "auto-install", "std", "track-caller"]
anyhow = []
auto-install = []
std = []
track-caller = []

[dependencies]
indenter = { workspace = true }
once_cell = { workspace = true }
once_cell = { workspace = true, default-features = false, features = [
"alloc",
"race",
] }
pyo3 = { version = "0.24.0", optional = true, default-features = false }

[build-dependencies]
Expand Down
5 changes: 4 additions & 1 deletion eyre/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ fn main() {
}

// https://github.com/rust-lang/rust/issues/47809 [rustc-1.46]
ac.emit_expression_cfg("std::panic::Location::caller", "track_caller");
if ac.probe_rustc_version(1, 46) {
autocfg::emit("track_caller");
}

if ac.probe_rustc_version(1, 52) {
autocfg::emit("eyre_no_fmt_arguments_as_str");
Expand All @@ -33,6 +35,7 @@ fn main() {
autocfg::emit("eyre_no_fmt_args_capture");
}

#[cfg(feature = "std")]
if ac.probe_rustc_version(1, 65) {
autocfg::emit("backtrace")
}
Expand Down
4 changes: 2 additions & 2 deletions eyre/src/backtrace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ macro_rules! capture_backtrace {
};
}
/// Capture a backtrace iff there is not already a backtrace in the error chain
#[cfg(generic_member_access)]
#[cfg(all(generic_member_access, backtrace))]
macro_rules! backtrace_if_absent {
($err:expr) => {
match std::error::request_ref::<std::backtrace::Backtrace>($err as &dyn std::error::Error) {
Expand All @@ -28,7 +28,7 @@ macro_rules! backtrace_if_absent {
};
}

#[cfg(not(generic_member_access))]
#[cfg(not(all(generic_member_access, backtrace)))]
macro_rules! backtrace_if_absent {
($err:expr) => {
capture_backtrace!()
Expand Down
2 changes: 1 addition & 1 deletion eyre/src/chain.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use self::ChainState::*;
use crate::StdError;

use std::vec;
use alloc::vec::{self, Vec};

pub(crate) use crate::Chain;

Expand Down
4 changes: 2 additions & 2 deletions eyre/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ mod ext {

impl<E> StdError for E
where
E: std::error::Error + Send + Sync + 'static,
E: core::error::Error + Send + Sync + 'static,
{
fn ext_report<D>(self, msg: D) -> Report
where
Expand Down Expand Up @@ -137,7 +137,7 @@ where
E: StdError + 'static,
{
#[cfg(generic_member_access)]
fn provide<'a>(&'a self, request: &mut std::error::Request<'a>) {
fn provide<'a>(&'a self, request: &mut core::error::Request<'a>) {
self.error.provide(request);
}

Expand Down
3 changes: 2 additions & 1 deletion eyre/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::chain::Chain;
use crate::ptr::{MutPtr, OwnedPtr, RefPtr};
use crate::EyreHandler;
use crate::{Report, StdError};
use alloc::boxed::Box;
use core::any::TypeId;
use core::fmt::{self, Debug, Display};
use core::mem::{self, ManuallyDrop};
Expand Down Expand Up @@ -856,7 +857,7 @@ where
E: StdError,
{
#[cfg(generic_member_access)]
fn provide<'a>(&'a self, request: &mut std::error::Request<'a>) {
fn provide<'a>(&'a self, request: &mut core::error::Request<'a>) {
self._object.provide(request)
}

Expand Down
1 change: 1 addition & 0 deletions eyre/src/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
// (&error).eyre_kind().new(error)

use crate::Report;
use alloc::boxed::Box;
use core::fmt::{Debug, Display};

use crate::StdError;
Expand Down
22 changes: 12 additions & 10 deletions eyre/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@
clippy::new_ret_no_self,
clippy::wrong_self_convention
)]
#![cfg_attr(not(feature = "std"), no_std)]

extern crate alloc;

Expand All @@ -381,13 +382,14 @@ use crate::backtrace::Backtrace;
use crate::error::ErrorImpl;
use core::fmt::{Debug, Display};

use std::error::Error as StdError;
use core::error::Error as StdError;

use alloc::boxed::Box;
pub use eyre as format_err;
/// Compatibility re-export of `eyre` for interop with `anyhow`
#[cfg(feature = "anyhow")]
pub use eyre as anyhow;
use once_cell::sync::OnceCell;
use once_cell::race::OnceBox;
use ptr::OwnedPtr;
#[cfg(feature = "anyhow")]
#[doc(hidden)]
Expand Down Expand Up @@ -485,7 +487,7 @@ pub struct Report {
type ErrorHook =
Box<dyn Fn(&(dyn StdError + 'static)) -> Box<dyn EyreHandler> + Sync + Send + 'static>;

static HOOK: OnceCell<ErrorHook> = OnceCell::new();
static HOOK: OnceBox<ErrorHook> = OnceBox::new();

/// Error indicating that `set_hook` was unable to install the provided ErrorHook
#[derive(Debug, Clone, Copy)]
Expand Down Expand Up @@ -596,7 +598,7 @@ impl StdError for InstallError {}
/// }
/// ```
pub fn set_hook(hook: ErrorHook) -> Result<(), InstallError> {
HOOK.set(hook).map_err(|_| InstallError)
HOOK.set(Box::new(hook)).map_err(|_| InstallError)
}

#[cfg_attr(track_caller, track_caller)]
Expand All @@ -610,14 +612,14 @@ fn capture_handler(error: &(dyn StdError + 'static)) -> Box<dyn EyreHandler> {

#[cfg(feature = "auto-install")]
let hook = HOOK
.get_or_init(|| Box::new(DefaultHandler::default_with))
.get_or_init(|| Box::new(Box::new(DefaultHandler::default_with)))
.as_ref();

let mut handler = hook(error);

#[cfg(track_caller)]
{
handler.track_caller(std::panic::Location::caller())
handler.track_caller(core::panic::Location::caller())
}

handler
Expand Down Expand Up @@ -734,7 +736,7 @@ pub trait EyreHandler: core::any::Any + Send + Sync {

/// Store the location of the caller who constructed this error report
#[allow(unused_variables)]
fn track_caller(&mut self, location: &'static std::panic::Location<'static>) {}
fn track_caller(&mut self, location: &'static core::panic::Location<'static>) {}
}

/// The default provided error report handler for `eyre::Report`.
Expand All @@ -745,7 +747,7 @@ pub trait EyreHandler: core::any::Any + Send + Sync {
pub struct DefaultHandler {
backtrace: Option<Backtrace>,
#[cfg(track_caller)]
location: Option<&'static std::panic::Location<'static>>,
location: Option<&'static core::panic::Location<'static>>,
}

impl DefaultHandler {
Expand Down Expand Up @@ -838,7 +840,7 @@ impl EyreHandler for DefaultHandler {
}
}

#[cfg(generic_member_access)]
#[cfg(all(generic_member_access, backtrace))]
{
use std::backtrace::BacktraceStatus;

Expand All @@ -860,7 +862,7 @@ impl EyreHandler for DefaultHandler {
}

#[cfg(track_caller)]
fn track_caller(&mut self, location: &'static std::panic::Location<'static>) {
fn track_caller(&mut self, location: &'static core::panic::Location<'static>) {
self.location = Some(location);
}
}
Expand Down
4 changes: 3 additions & 1 deletion eyre/src/ptr.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use std::{marker::PhantomData, ptr::NonNull};
use core::{marker::PhantomData, ptr::NonNull};

use alloc::boxed::Box;

/// An owned pointer
///
Expand Down
3 changes: 2 additions & 1 deletion eyre/src/wrapper.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::StdError;
use alloc::boxed::Box;
use core::fmt::{self, Debug, Display};

#[repr(transparent)]
Expand Down Expand Up @@ -83,7 +84,7 @@ impl Display for BoxedError {

impl StdError for BoxedError {
#[cfg(generic_member_access)]
fn provide<'a>(&'a self, request: &mut std::error::Request<'a>) {
fn provide<'a>(&'a self, request: &mut core::error::Request<'a>) {
self.0.provide(request);
}

Expand Down