Skip to content
Merged
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
11 changes: 10 additions & 1 deletion packages/libs/error-stack/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,18 @@ All notable changes to `error-stack` will be documented in this file.

## Planned

- Support for [`serde`](https://serde.rs) (`Serialize` only)
- Support for [`defmt`](https://defmt.ferrous-systems.com)

## 0.3.0 - Unreleased

### Breaking Changes

- Remove all previously deprecated methods ([#1485](https://github.com/hashintel/hash/pull/1485))

### Features

- Add serializing support using [`serde`](https://serde.rs) ([#1290](https://github.com/hashintel/hash/pull/1290))

## [0.2.4](https://github.com/hashintel/hash/tree/error-stack%400.2.4/packages/libs/error-stack) - 2022-11-04

- The output of [`Location`](https://doc.rust-lang.org/std/panic/struct.Location.html) is no longer hard-coded and can now be adjusted through hooks. ([#1237](https://github.com/hashintel/hash/pull/1237))
Expand Down
9 changes: 2 additions & 7 deletions packages/libs/error-stack/src/compat/anyhow.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use core::panic::Location;

use anyhow::Error as AnyhowError;

use crate::{Frame, IntoReportCompat, Report, Result};
Expand All @@ -21,11 +19,8 @@ impl<T> IntoReportCompat for core::result::Result<T, AnyhowError> {
.collect::<alloc::vec::Vec<_>>();

#[cfg_attr(not(feature = "std"), allow(unused_mut))]
let mut report = Report::from_frame(Frame::from_anyhow(
anyhow,
Location::caller(),
alloc::boxed::Box::new([]),
));
let mut report =
Report::from_frame(Frame::from_anyhow(anyhow, alloc::boxed::Box::new([])));

#[cfg(feature = "std")]
for source in sources {
Expand Down
5 changes: 1 addition & 4 deletions packages/libs/error-stack/src/compat/eyre.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use core::panic::Location;

use eyre::Report as EyreReport;

use crate::{Frame, IntoReportCompat, Report, Result};
Expand All @@ -20,8 +18,7 @@ impl<T> IntoReportCompat for core::result::Result<T, EyreReport> {
.collect::<alloc::vec::Vec<_>>();

#[cfg_attr(not(feature = "std"), allow(unused_mut))]
let mut report =
Report::from_frame(Frame::from_eyre(eyre, Location::caller(), Box::new([])));
let mut report = Report::from_frame(Frame::from_eyre(eyre, Box::new([])));

for source in sources {
report = report.attach_printable(source);
Expand Down
4 changes: 3 additions & 1 deletion packages/libs/error-stack/src/compat/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
//!
//! [`Report`]: crate::Report

use crate::Report;

#[cfg(feature = "anyhow")]
mod anyhow;
#[cfg(feature = "eyre")]
Expand Down Expand Up @@ -32,5 +34,5 @@ pub trait IntoReportCompat: Sized {
/// Converts the [`Err`] variant of the [`Result`] to a [`Report`]
///
/// [`Report`]: crate::Report
fn into_report(self) -> crate::Result<Self::Ok, Self::Err>;
fn into_report(self) -> Result<Self::Ok, Report<Self::Err>>;
}
1 change: 0 additions & 1 deletion packages/libs/error-stack/src/fmt/hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,6 @@ fn into_boxed_hook<T: Send + Sync + 'static>(
/// [`SpanTrace`]: tracing_error::SpanTrace
/// [`Display`]: core::fmt::Display
/// [`Debug`]: core::fmt::Debug
/// [`Frame`]: crate::Frame
/// [`.insert()`]: Hooks::insert
#[cfg(feature = "std")]
pub(crate) struct Hooks {
Expand Down
10 changes: 0 additions & 10 deletions packages/libs/error-stack/src/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -943,11 +943,6 @@ fn debug_frame(

impl<C> Debug for Report<C> {
fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result {
#[cfg(feature = "std")]
if let Some(result) = Report::invoke_debug_hook(|hook| hook(self.generalized(), fmt)) {
return result;
}

#[cfg(feature = "std")]
let mut context = HookContext::new(fmt.alternate());

Expand Down Expand Up @@ -1017,11 +1012,6 @@ impl<C> Debug for Report<C> {

impl<Context> Display for Report<Context> {
fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result {
#[cfg(feature = "std")]
if let Some(result) = Report::invoke_display_hook(|hook| hook(self.generalized(), fmt)) {
return result;
}

for (index, frame) in self
.frames()
.filter_map(|frame| match frame.kind() {
Expand Down
49 changes: 10 additions & 39 deletions packages/libs/error-stack/src/frame/frame_impl.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
use alloc::boxed::Box;
#[cfg(nightly)]
use core::any::Demand;
#[cfg(any(feature = "anyhow", feature = "eyre"))]
use core::fmt;
use core::{
any::Any,
fmt::{Debug, Display},
panic::Location,
};
use core::{any::Any, fmt};

use crate::{AttachmentKind, Context, Frame, FrameKind};

Expand Down Expand Up @@ -77,7 +71,9 @@ struct PrintableAttachmentFrame<A> {
attachment: A,
}

impl<A: 'static + Debug + Display + Send + Sync> FrameImpl for PrintableAttachmentFrame<A> {
impl<A: 'static + fmt::Debug + fmt::Display + Send + Sync> FrameImpl
for PrintableAttachmentFrame<A>
{
fn kind(&self) -> FrameKind<'_> {
FrameKind::Attachment(AttachmentKind::Printable(&self.attachment))
}
Expand Down Expand Up @@ -195,61 +191,41 @@ impl FrameImpl for EyreContext {

impl Frame {
/// Creates a frame from a [`Context`].
pub(crate) fn from_context<C>(
context: C,
location: &'static Location<'static>,
sources: Box<[Self]>,
) -> Self
pub(crate) fn from_context<C>(context: C, sources: Box<[Self]>) -> Self
where
C: Context,
{
Self {
frame: Box::new(ContextFrame { context }),
location,
sources,
}
}

/// Creates a frame from an attachment.
pub(crate) fn from_attachment<A>(
attachment: A,
location: &'static Location<'static>,
sources: Box<[Self]>,
) -> Self
pub(crate) fn from_attachment<A>(attachment: A, sources: Box<[Self]>) -> Self
where
A: Send + Sync + 'static,
{
Self {
frame: Box::new(AttachmentFrame { attachment }),
location,
sources,
}
}

/// Creates a frame from an [`anyhow::Error`].
#[cfg(feature = "anyhow")]
pub(crate) fn from_anyhow(
error: anyhow::Error,
location: &'static Location<'static>,
sources: Box<[Self]>,
) -> Self {
pub(crate) fn from_anyhow(error: anyhow::Error, sources: Box<[Self]>) -> Self {
Self {
frame: Box::new(AnyhowContext(error)),
location,
sources,
}
}

/// Creates a frame from an [`eyre::Report`].
#[cfg(feature = "eyre")]
pub(crate) fn from_eyre(
report: eyre::Report,
location: &'static Location<'static>,
sources: Box<[Self]>,
) -> Self {
pub(crate) fn from_eyre(report: eyre::Report, sources: Box<[Self]>) -> Self {
Self {
frame: Box::new(EyreContext(report)),
location,
sources,
}
}
Expand All @@ -258,17 +234,12 @@ impl Frame {
///
/// [`Debug`]: core::fmt::Debug
/// [`Display`]: core::fmt::Display
pub(crate) fn from_printable_attachment<A>(
attachment: A,
location: &'static Location<'static>,
sources: Box<[Self]>,
) -> Self
pub(crate) fn from_printable_attachment<A>(attachment: A, sources: Box<[Self]>) -> Self
where
A: Display + Debug + Send + Sync + 'static,
A: fmt::Display + fmt::Debug + Send + Sync + 'static,
{
Self {
frame: Box::new(PrintableAttachmentFrame { attachment }),
location,
sources,
}
}
Expand Down
30 changes: 1 addition & 29 deletions packages/libs/error-stack/src/frame/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ mod kind;
use alloc::boxed::Box;
#[cfg(nightly)]
use core::any::{self, Demand, Provider};
use core::{any::TypeId, fmt, panic::Location};
use core::{any::TypeId, fmt};

use self::frame_impl::FrameImpl;
pub use self::kind::{AttachmentKind, FrameKind};
Expand All @@ -22,31 +22,10 @@ pub use self::kind::{AttachmentKind, FrameKind};
/// [`Report::request_ref()`]: crate::Report::request_ref
pub struct Frame {
frame: Box<dyn FrameImpl>,
location: &'static Location<'static>,
sources: Box<[Frame]>,
}

impl Frame {
/// Returns the location where this `Frame` was created.
#[must_use]
#[deprecated(
since = "0.2.4",
note = "`location()` has been replaced with an additional attachment containing \
`Location<'static>` for each `Context`, similar to how `Backtrace` and \
`SpanTrace` are handled. Note: This means that once `location()` is removed you \
won't be able to get location of attachments anymore."
)]
pub const fn location(&self) -> &'static Location<'static> {
self.location
}

#[allow(missing_docs)]
#[must_use]
#[deprecated(since = "0.2.0", note = "use `sources()` instead")]
pub const fn source(&self) -> Option<&Self> {
self.sources().first()
}

/// Returns a shared reference to the source of this `Frame`.
///
/// This corresponds to the `Frame` below this one in a [`Report`].
Expand All @@ -57,13 +36,6 @@ impl Frame {
&self.sources
}

#[allow(missing_docs)]
#[must_use]
#[deprecated(since = "0.2.0", note = "use `sources_mut()` instead")]
pub fn source_mut(&mut self) -> Option<&mut Self> {
self.sources_mut().first_mut()
}

/// Returns a mutable reference to the sources of this `Frame`.
///
/// This corresponds to the `Frame` below this one in a [`Report`].
Expand Down
Loading