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-196: Move error-stack-experimental into error-stack #5181

Merged
merged 11 commits into from
Sep 23, 2024
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
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
4 changes: 2 additions & 2 deletions libs/error-stack/.justfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ clippy *arguments:
[private]
test *arguments:
@just install-cargo-nextest
@just install-cargo-hack

RUST_BACKTRACE=1 cargo hack --optional-deps --feature-powerset {{cargo-hack-groups}} nextest run --cargo-profile {{profile}} {{arguments}}
RUST_BACKTRACE=1 cargo nextest run --all-features --all-targets --cargo-profile {{profile}} {{arguments}}
RUST_BACKTRACE=1 cargo nextest run --no-default-features --all-targets --cargo-profile {{profile}} {{arguments}}
RUST_BACKTRACE=1 cargo test --profile {{profile}} --all-features --doc {{arguments}}

[private]
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.
///
Comment on lines +94 to +97
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to mention this everywhere as the documentation is properly generating this:
image

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just wanted to make sure to mention that it is exempt from semver guarantees and why, not necessarily that it's unstable.

/// [`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 Expand Up @@ -187,8 +197,8 @@ where
#[cfg(test)]
mod tests {
#![allow(clippy::integer_division_remainder_used)]
use alloc::{collections::BTreeSet, vec::Vec};
use core::fmt;
use std::collections::HashSet;

use super::*;

Expand Down Expand Up @@ -216,7 +226,7 @@ mod tests {
let result: Result<Vec<_>, [CustomError]> = iter.try_collect_reports();
let report = result.expect_err("should have failed");

let contexts: HashSet<_> = report.current_contexts().collect();
let contexts: BTreeSet<_> = report.current_contexts().collect();
assert_eq!(contexts.len(), 2);
assert!(contexts.contains(&CustomError(1)));
assert!(contexts.contains(&CustomError(3)));
Expand All @@ -235,7 +245,7 @@ mod tests {
let result: Result<Vec<_>, [CustomError]> = iter.try_collect_reports_bounded(3);
let report = result.expect_err("should have failed");

let contexts: HashSet<_> = report.current_contexts().collect();
let contexts: BTreeSet<_> = report.current_contexts().collect();
assert_eq!(contexts.len(), 3);
assert!(contexts.contains(&CustomError(1)));
assert!(contexts.contains(&CustomError(3)));
Expand Down Expand Up @@ -265,7 +275,7 @@ mod tests {
let result: Result<Vec<_>, [CustomError]> = iter.try_collect_reports();
let report = result.expect_err("should have failed");

let contexts: HashSet<_> = report.current_contexts().collect();
let contexts: BTreeSet<_> = report.current_contexts().collect();
assert_eq!(contexts.len(), 2);
assert!(contexts.contains(&CustomError(1)));
assert!(contexts.contains(&CustomError(3)));
Expand Down
Loading
Loading