Skip to content

Commit

Permalink
GEN-196: Move error-stack-experimental into error-stack (#5181)
Browse files Browse the repository at this point in the history
  • Loading branch information
indietyp authored Sep 21, 2024
1 parent 402cf68 commit d6c4719
Show file tree
Hide file tree
Showing 19 changed files with 828 additions and 231 deletions.
15 changes: 3 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ members = [
"libs/deer/macros",
"libs/error-stack",
"libs/error-stack/macros",
"libs/error-stack/experimental",
"libs/sarif",
]
default-members = [
Expand Down
2 changes: 2 additions & 0 deletions libs/error-stack/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ All notable changes to `error-stack` will be documented in this file.
### Features

- Report has been split into `Report<C>` and `Report<[C]>` to distinguish between a group of related errors and a single error. These errors can still be nested.
- Introduce a new `unstable` flag, which is used to enable unstable features, these features are not covered by semver and may be modified or removed at any time.

### Breaking Changes

- `Extend` is no longer implemented by `Report<C>`, instead it is implemented on `Report<[C]>`, either use `From` or `Report::expand` to convert between `Report<C>` into `Report<[C]>`.
- `extend_one` has been renamed to `push` and is only implemented on `Report<[C]>`.
- `bail!(report,)` has been removed, one must now use `bail!(report)`. This is in preparation for the unstable `bail!` macro that allows to construct `Report<[C]>`.

## [0.5.0](https://github.com/hashintel/hash/tree/error-stack%400.5.0/libs/error-stack) - 2024-07-12

Expand Down
7 changes: 7 additions & 0 deletions libs/error-stack/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ exclude = ["package.json", "macros", "experimental"]
anyhow = { version = ">=1.0.73", public = true, default-features = false, optional = true }
eyre = { version = ">=0.6", public = true, default-features = false, optional = true }
serde = { version = ">=1", default-features = false, public = true, optional = true }
futures-core = { workspace = true, public = true, optional = true }

# Private workspace dependencies
pin-project-lite = { workspace = true, optional = true }

# Private third-party dependencies
spin = { version = ">=0.9", default-features = false, optional = true, features = ['rwlock', 'once'] }
Expand All @@ -42,6 +44,7 @@ supports-color = { workspace = true }
supports-unicode = { workspace = true }
owo-colors = { workspace = true }
thiserror = { workspace = true }
futures-util.workspace = true

[build-dependencies]
rustc_version = { workspace = true }
Expand All @@ -59,6 +62,10 @@ hooks = ['dep:spin'] # Enables hooks on `no-std` platforms using spin locks
anyhow = ["dep:anyhow"] # Provides `into_report` to convert `anyhow::Error` to `Report`
eyre = ["dep:eyre", "std"] # Provides `into_report` to convert `eyre::Report` to `Report`

futures = ["dep:futures-core", "dep:pin-project-lite"] # Provides support for `futures` types, such as stream.

unstable = [] # Enables unstable features that are not covered under any stability guarantees

[lints]
workspace = true

Expand Down
38 changes: 0 additions & 38 deletions libs/error-stack/experimental/Cargo.toml

This file was deleted.

5 changes: 0 additions & 5 deletions libs/error-stack/experimental/LICENSE.md

This file was deleted.

19 changes: 0 additions & 19 deletions libs/error-stack/experimental/README.md

This file was deleted.

10 changes: 0 additions & 10 deletions libs/error-stack/experimental/build.rs

This file was deleted.

9 changes: 0 additions & 9 deletions libs/error-stack/experimental/package.json

This file was deleted.

12 changes: 0 additions & 12 deletions libs/error-stack/experimental/src/lib.rs

This file was deleted.

102 changes: 0 additions & 102 deletions libs/error-stack/experimental/src/result.rs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use error_stack::{Context, Report, Result};
use crate::{Context, Report, Result};

// inspired by the implementation in `std`, see: https://doc.rust-lang.org/1.81.0/src/core/iter/adapters/mod.rs.html#157
// except with the removal of the Try trait, as it is unstable.
Expand Down Expand Up @@ -81,10 +81,22 @@ where
report.map_or_else(|| Ok(value), |report| Err(report))
}

/// An extension trait for iterators that allows collecting items while handling errors.
/// An extension trait for iterators that enables error-aware collection of items.
///
/// This trait provides additional functionality to iterators that yield `Result` items,
/// allowing them to be collected into a container while propagating any errors encountered.
/// This trait enhances iterators yielding `Result` items by providing methods to
/// collect successful items into a container while aggregating encountered errors.
///
/// # Performance Considerations
///
/// These methods may have performance implications as they potentially iterate
/// through the entire collection, even after encountering errors.
///
/// # Unstable Feature
///
/// This trait is currently available only under the `unstable` feature flag and
/// does not adhere to semver guarantees. Its API may change in future releases.
///
/// [`Report`]: crate::Report
pub trait TryReportIteratorExt<C> {
/// The type of the successful items in the iterator.
type Ok;
Expand All @@ -104,9 +116,8 @@ pub trait TryReportIteratorExt<C> {
/// # Examples
///
/// ```
/// use error_stack::{Result, ResultExt, Report};
/// use error_stack::{Result, Report, TryReportIteratorExt};
/// use std::io;
/// use error_stack_experimental::TryReportIteratorExt;
///
/// fn fetch_fail() -> Result<u8, io::Error> {
/// # stringify! {
Expand Down Expand Up @@ -140,9 +151,8 @@ pub trait TryReportIteratorExt<C> {
/// # Examples
///
/// ```
/// use error_stack::{Result, ResultExt, Report};
/// use error_stack::{Result, Report, TryReportIteratorExt};
/// use std::io;
/// use error_stack_experimental::TryReportIteratorExt;
///
/// fn fetch_fail() -> Result<u8, io::Error> {
/// # stringify! {
Expand Down
19 changes: 19 additions & 0 deletions libs/error-stack/src/ext/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//! Extension traits for `Report` and `Result`.
//!
//! These traits are currently unstable and require the `unstable` feature flag to be enabled.
//! They provide additional functionality and convenience methods for error handling and
//! manipulation.
//!
//! # Note
//!
//! The traits and methods in this module are subject to change and may be modified or
//! removed in future versions. Use them with caution in production environments.
pub(crate) mod iter;
#[cfg(feature = "futures")]
pub(crate) mod stream;
pub(crate) mod tuple;

#[cfg(feature = "futures")]
pub use self::stream::{TryCollectReports, TryReportStreamExt};
pub use self::{iter::TryReportIteratorExt, tuple::TryReportTupleExt};
Loading

0 comments on commit d6c4719

Please sign in to comment.