Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GEN-53: Upgrade error-stack toolchain and use Error::provide #2912

Merged
merged 2 commits into from
Aug 16, 2023
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
5 changes: 5 additions & 0 deletions .github/renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,11 @@
"matchPackagePatterns": ["^tracing[-_]?"],
"excludePackageNames": ["tracing-opentelemetry"],
"groupName": "`tracing` crates"
},
indietyp marked this conversation as resolved.
Show resolved Hide resolved
{
"matchManagers": ["cargo"],
"matchFileNames": ["libs/error-stack/Cargo.toml"],
"excludeDepNames": ["anyhow"]
}
],
"regexManagers": [
Expand Down
2 changes: 1 addition & 1 deletion libs/error-stack/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ categories = ["rust-patterns", "no-std"]

[dependencies]
tracing-error = { version = "0.2", optional = true, default_features = false }
anyhow = { version = ">=1.0.65, <=1.0.72", default-features = false, optional = true }
anyhow = { version = ">=1.0.73", default-features = false, optional = true }
eyre = { version = "0.6", default-features = false, optional = true }
serde = { version = "1", default-features = false, optional = true }
spin = { version = "0.9", default-features = false, optional = true, features = ['rwlock', 'once'] }
Expand Down
2 changes: 1 addition & 1 deletion libs/error-stack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

[![crates.io](https://img.shields.io/crates/v/error-stack)][crates.io]
[![libs.rs](https://img.shields.io/badge/libs.rs-error--stack-orange)][libs.rs]
[![rust-version](https://img.shields.io/static/v1?label=Rust&message=1.63.0/nightly-2023-08-14&color=blue)][rust-version]
[![rust-version](https://img.shields.io/static/v1?label=Rust&message=1.63.0/nightly-2023-08-15&color=blue)][rust-version]
[![documentation](https://img.shields.io/docsrs/error-stack)][documentation]
[![license](https://img.shields.io/crates/l/error-stack)][license]
[![discord](https://img.shields.io/discord/840573247803097118)][discord]
Expand Down
2 changes: 1 addition & 1 deletion libs/error-stack/macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ proc-macro = true
[dependencies]

[dev-dependencies]
error-stack = { version = "0.3.1", default-features = false }
error-stack = { path = "..", default-features = false }
2 changes: 1 addition & 1 deletion libs/error-stack/macros/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

[![crates.io](https://img.shields.io/crates/v/error-stack-macros)][crates.io]
[![libs.rs](https://img.shields.io/badge/libs.rs-error--stack--macros-orange)][libs.rs]
[![rust-version](https://img.shields.io/static/v1?label=Rust&message=1.63.0/nightly-2023-08-14&color=blue)][rust-version]
[![rust-version](https://img.shields.io/static/v1?label=Rust&message=1.63.0/nightly-2023-08-15&color=blue)][rust-version]
[![documentation](https://img.shields.io/docsrs/error-stack-macros)][documentation]
[![license](https://img.shields.io/crates/l/error-stack)][license]
[![discord](https://img.shields.io/discord/840573247803097118)][discord]
Expand Down
2 changes: 1 addition & 1 deletion libs/error-stack/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[toolchain]
# Please also update the badges in `README.md`s (`error-stack` and `error-stack-macros`), and `src/lib.rs`
channel = "nightly-2023-08-14"
channel = "nightly-2023-08-15"
components = ['rustfmt', 'clippy', 'llvm-tools-preview', 'miri', 'rust-src']
10 changes: 5 additions & 5 deletions libs/error-stack/src/context.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use core::fmt;
#[cfg(nightly)]
use core::{any::Demand, error::Error};
use core::error::{Error, Request};
use core::fmt;
#[cfg(all(not(nightly), feature = "std"))]
use std::error::Error;

Expand Down Expand Up @@ -61,7 +61,7 @@ pub trait Context: fmt::Display + fmt::Debug + Send + Sync + 'static {
/// Provide values which can then be requested by [`Report`].
#[cfg(nightly)]
#[allow(unused_variables)]
fn provide<'a>(&'a self, demand: &mut Demand<'a>) {}
fn provide<'a>(&'a self, request: &mut Request<'a>) {}
}

impl<C> From<C> for Report<C>
Expand All @@ -78,7 +78,7 @@ where
#[cfg(any(nightly, feature = "std"))]
impl<C: Error + Send + Sync + 'static> Context for C {
#[cfg(nightly)]
fn provide<'a>(&'a self, demand: &mut Demand<'a>) {
Error::provide(self, demand);
fn provide<'a>(&'a self, request: &mut Request<'a>) {
Error::provide(self, request);
}
}
13 changes: 6 additions & 7 deletions libs/error-stack/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use core::fmt;
#[cfg(nightly)]
use core::{
any::{Demand, Provider},
error::Error,
};
use core::error::{Error, Request};
use core::fmt;
#[cfg(not(nightly))]
use std::error::Error;

Expand Down Expand Up @@ -37,7 +34,9 @@ impl<C> fmt::Display for ReportError<C> {

impl<C> Error for ReportError<C> {
#[cfg(nightly)]
fn provide<'a>(&'a self, demand: &mut Demand<'a>) {
self.0.frames().for_each(|frame| frame.provide(demand));
fn provide<'a>(&'a self, request: &mut Request<'a>) {
self.0
.frames()
.for_each(|frame| frame.as_error().provide(request));
}
}
4 changes: 2 additions & 2 deletions libs/error-stack/src/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
//! [`Report::install_debug_hook`] calls determines the order of the rendered output. Note, that
//! Hooks get called on all values provided by [`Context::provide`], but not on the [`Context`]
//! object itself. Therefore if you want to call a hook on a [`Context`] to print in addition to its
//! [`Display`] implementation, you may want to call [`demand.provide_ref(self)`] inside of
//! [`Display`] implementation, you may want to call [`request.provide_ref(self)`] inside of
//! [`Context::provide`].
//!
//! [`demand.provide_ref(self)`]: core::any::Demand::provide_ref
//! [`request.provide_ref(self)`]: core::error::Request::provide_ref
//!
//! Hook functions need to be [`Fn`] and **not** [`FnMut`], which means they are unable to directly
//! mutate state outside of the closure.
Expand Down
14 changes: 6 additions & 8 deletions libs/error-stack/src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ mod kind;

use alloc::boxed::Box;
#[cfg(nightly)]
use core::any::{self, Demand, Provider};
use core::error::{self, Error};
use core::{any::TypeId, fmt};

use self::frame_impl::FrameImpl;
Expand Down Expand Up @@ -59,7 +59,7 @@ impl Frame {
where
T: ?Sized + 'static,
{
any::request_ref(self)
error::request_ref(self.as_error())
}

/// Requests the value of `T` from the `Frame` if provided.
Expand All @@ -69,7 +69,7 @@ impl Frame {
where
T: 'static,
{
any::request_value(self)
error::request_value(self.as_error())
}

/// Returns if `T` is the held context or attachment by this frame.
Expand All @@ -95,12 +95,10 @@ impl Frame {
pub fn type_id(&self) -> TypeId {
self.frame.as_any().type_id()
}
}

#[cfg(nightly)]
impl Provider for Frame {
fn provide<'a>(&'a self, demand: &mut Demand<'a>) {
self.frame.provide(demand);
#[cfg(nightly)]
pub(crate) fn as_error(&self) -> &impl Error {
&self.frame
}
}

Expand Down
54 changes: 37 additions & 17 deletions libs/error-stack/src/frame/frame_impl.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use alloc::boxed::Box;
#[cfg(nightly)]
use core::any::Demand;
use core::error::{Error, Request};
use core::{any::Any, fmt};

use crate::{AttachmentKind, Context, Frame, FrameKind};
Expand All @@ -15,7 +15,28 @@ pub(super) trait FrameImpl: Send + Sync + 'static {

/// Provide values which can then be requested.
#[cfg(nightly)]
fn provide<'a>(&'a self, demand: &mut Demand<'a>);
fn provide<'a>(&'a self, request: &mut Request<'a>);
}

#[cfg(nightly)]
impl fmt::Debug for Box<dyn FrameImpl> {
fn fmt(&self, _: &mut fmt::Formatter<'_>) -> fmt::Result {
unreachable!()
}
}

#[cfg(nightly)]
impl fmt::Display for Box<dyn FrameImpl> {
fn fmt(&self, _: &mut fmt::Formatter<'_>) -> fmt::Result {
unreachable!()
}
}

#[cfg(nightly)]
impl Error for Box<dyn FrameImpl> {
fn provide<'a>(&'a self, request: &mut Request<'a>) {
(**self).provide(request);
}
}

struct ContextFrame<C> {
Expand All @@ -36,8 +57,8 @@ impl<C: Context> FrameImpl for ContextFrame<C> {
}

#[cfg(nightly)]
fn provide<'a>(&'a self, demand: &mut Demand<'a>) {
Context::provide(&self.context, demand);
fn provide<'a>(&'a self, request: &mut Request<'a>) {
Context::provide(&self.context, request);
}
}

Expand All @@ -59,8 +80,8 @@ impl<A: 'static + Send + Sync> FrameImpl for AttachmentFrame<A> {
}

#[cfg(nightly)]
fn provide<'a>(&'a self, demand: &mut Demand<'a>) {
demand.provide_ref(&self.attachment);
fn provide<'a>(&'a self, request: &mut Request<'a>) {
request.provide_ref(&self.attachment);
}
}

Expand All @@ -84,8 +105,8 @@ impl<A: 'static + fmt::Debug + fmt::Display + Send + Sync> FrameImpl
}

#[cfg(nightly)]
fn provide<'a>(&'a self, demand: &mut Demand<'a>) {
demand.provide_ref(&self.attachment);
fn provide<'a>(&'a self, request: &mut Request<'a>) {
request.provide_ref(&self.attachment);
}
}

Expand All @@ -108,11 +129,10 @@ impl fmt::Display for AnyhowContext {

#[cfg(feature = "anyhow")]
impl Context for AnyhowContext {
// `Provider` is only implemented for `anyhow::Error` on `std`
#[cfg(all(nightly, feature = "std"))]
#[inline]
fn provide<'a>(&'a self, demand: &mut Demand<'a>) {
core::any::Provider::provide(&self.0, demand);
fn provide<'a>(&'a self, request: &mut Request<'a>) {
request.provide_ref(self.0.backtrace());
}
}

Expand All @@ -132,8 +152,8 @@ impl FrameImpl for AnyhowContext {

#[cfg(nightly)]
#[inline]
fn provide<'a>(&'a self, demand: &mut Demand<'a>) {
Context::provide(self, demand);
fn provide<'a>(&'a self, request: &mut Request<'a>) {
Context::provide(self, request);
}
}

Expand All @@ -158,8 +178,8 @@ impl fmt::Display for EyreContext {
impl Context for EyreContext {
#[cfg(nightly)]
#[inline]
fn provide<'a>(&'a self, _demand: &mut Demand<'a>) {
// `eyre::Report` does not implement `Provider`
fn provide<'a>(&'a self, request: &mut Request<'a>) {
Error::provide(self.0.as_ref() as &dyn Error, request);
}
}

Expand All @@ -179,8 +199,8 @@ impl FrameImpl for EyreContext {

#[cfg(nightly)]
#[inline]
fn provide<'a>(&'a self, demand: &mut Demand<'a>) {
Context::provide(self, demand);
fn provide<'a>(&'a self, request: &mut Request<'a>) {
Context::provide(self, request);
}
}

Expand Down
9 changes: 4 additions & 5 deletions libs/error-stack/src/hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,14 @@ impl Report<()> {
/// ```rust
/// # // this is a lot of boilerplate, if you find a better way, please change this!
/// # // with #![cfg(nightly)] docsrs will complain that there's no main in non-nightly
/// # #![cfg_attr(nightly, feature(error_generic_member_access, provide_any))]
/// # #![cfg_attr(nightly, feature(error_in_core, error_generic_member_access))]
/// # const _: &'static str = r#"
/// #![feature(error_generic_member_access, provide_any)]
/// #![feature(error_generic_member_access)]
/// # "#;
///
/// # #[cfg(nightly)]
/// # mod nightly {
/// use std::any::Demand;
/// use std::error::Error;
/// use std::error::{Request, Error};
/// use std::fmt::{Display, Formatter};
/// use error_stack::{Report, report};
///
Expand All @@ -104,7 +103,7 @@ impl Report<()> {
/// }
///
/// impl Error for UserError {
/// fn provide<'a>(&'a self, req: &mut Demand<'a>) {
/// fn provide<'a>(&'a self, req: &mut Request<'a>) {
/// req.provide_value(Suggestion("try better next time!"));
/// req.provide_ref(&self.code);
/// }
Expand Down
7 changes: 2 additions & 5 deletions libs/error-stack/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//!
//! [![crates.io](https://img.shields.io/crates/v/error-stack)][crates.io]
//! [![libs.rs](https://img.shields.io/badge/libs.rs-error--stack-orange)][libs.rs]
//! [![rust-version](https://img.shields.io/static/v1?label=Rust&message=1.63.0/nightly-2023-08-14&color=blue)][rust-version]
//! [![rust-version](https://img.shields.io/static/v1?label=Rust&message=1.63.0/nightly-2023-08-15&color=blue)][rust-version]
//! [![discord](https://img.shields.io/discord/840573247803097118)][discord]
//!
//! [crates.io]: https://crates.io/crates/error-stack
Expand Down Expand Up @@ -428,10 +428,7 @@
//! [`Debug`]: core::fmt::Debug
//! [`SpanTrace`]: tracing_error::SpanTrace
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(
nightly,
feature(provide_any, error_in_core, error_generic_member_access)
)]
#![cfg_attr(nightly, feature(error_in_core, error_generic_member_access))]
#![cfg_attr(all(doc, nightly), feature(doc_auto_cfg))]
#![cfg_attr(all(nightly, feature = "std"), feature(backtrace_frames))]
#![cfg_attr(
Expand Down
12 changes: 6 additions & 6 deletions libs/error-stack/src/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ use crate::{
/// consists of. Therefore it isn't guaranteed that [`request_ref()`] will only ever return a single
/// [`Backtrace`] or [`SpanTrace`].
///
/// [`provide`]: core::any::Provider::provide
/// [`provide`]: core::error::Error::provide
/// [`ErrorLayer`]: tracing_error::ErrorLayer
/// [`attach()`]: Self::attach
/// [`extend_one()`]: Self::extend_one
Expand Down Expand Up @@ -269,15 +269,15 @@ impl<C> Report<C> {
#[track_caller]
pub(crate) fn from_frame(frame: Frame) -> Self {
#[cfg(nightly)]
let location = core::any::request_ref::<Location>(&frame)
let location = core::error::request_ref::<Location>(&frame.as_error())
.is_none()
.then_some(Location::caller());

#[cfg(not(nightly))]
let location = Some(Location::caller());

#[cfg(all(nightly, feature = "std"))]
let backtrace = core::any::request_ref::<Backtrace>(&frame)
let backtrace = core::error::request_ref::<Backtrace>(&frame.as_error())
.filter(|backtrace| backtrace.status() == BacktraceStatus::Captured)
.is_none()
.then(Backtrace::capture);
Expand All @@ -286,7 +286,7 @@ impl<C> Report<C> {
let backtrace = Some(Backtrace::capture());

#[cfg(all(nightly, feature = "spantrace"))]
let span_trace = core::any::request_ref::<SpanTrace>(&frame)
let span_trace = core::error::request_ref::<SpanTrace>(&frame.as_error())
.filter(|span_trace| span_trace.status() == SpanTraceStatus::CAPTURED)
.is_none()
.then(SpanTrace::capture);
Expand Down Expand Up @@ -509,14 +509,14 @@ impl<C> Report<C> {
}

/// Creates an iterator of references of type `T` that have been [`attached`](Self::attach) or
/// that are [`provide`](core::any::Provider::provide)d by [`Context`] objects.
/// that are [`provide`](Error::provide)d by [`Context`] objects.
#[cfg(nightly)]
pub fn request_ref<T: ?Sized + Send + Sync + 'static>(&self) -> RequestRef<'_, T> {
RequestRef::new(&self.frames)
}

/// Creates an iterator of values of type `T` that have been [`attached`](Self::attach) or
/// that are [`provide`](core::any::Provider::provide)d by [`Context`] objects.
/// that are [`provide`](Error::provide)d by [`Context`] objects.
#[cfg(nightly)]
pub fn request_value<T: Send + Sync + 'static>(&self) -> RequestValue<'_, T> {
RequestValue::new(&self.frames)
Expand Down
Loading