diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9696e6f42c6..d95b18332c8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -550,31 +550,20 @@ jobs: toolchain: ${{ steps.publish.outputs.rust-toolchain }} working-directory: ${{ matrix.directory }} - - name: Install tools - if: always() && steps.publish.outputs.has-rust == 'true' && github.event_name == 'pull_request' || github.event_name == 'merge_group' - uses: taiki-e/install-action@2335425120e645291d84cec8194c63983a0c8ee5 # v2.41.10 - with: - tool: cargo-semver-checks - - name: Login run: | [[ -n "${{ secrets.CARGO_REGISTRY_TOKEN }}" ]] cargo login "${{ secrets.CARGO_REGISTRY_TOKEN }}" - - name: SemVer check - if: always() && steps.publish.outputs.has-rust == 'true' && github.event_name == 'pull_request' || github.event_name == 'merge_group' - working-directory: ${{ matrix.directory }} - run: cargo semver-checks check-release - - name: Publish (dry run) if: always() && steps.publish.outputs.has-rust == 'true' && github.event_name == 'pull_request' || github.event_name == 'merge_group' working-directory: ${{ matrix.directory }} - run: cargo publish --all-features --dry-run + run: cargo publish --all-features --dry-run --no-verify - name: Publish if: always() && steps.publish.outputs.has-rust == 'true' && github.event_name == 'push' && github.ref == 'refs/heads/main' working-directory: ${{ matrix.directory }} - run: cargo publish --all-features + run: cargo publish --all-features --no-verify passed: name: Tests passed diff --git a/Cargo.lock b/Cargo.lock index 57619ad749f..7de21baa4fc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -333,7 +333,7 @@ version = "0.0.0" dependencies = [ "codec", "derive-where", - "error-stack 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "error-stack 0.4.1", "futures", "graph-types", "reqwest", @@ -1186,7 +1186,7 @@ name = "codec" version = "0.0.0" dependencies = [ "derive-where", - "error-stack 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "error-stack 0.4.1", "harpc-wire-protocol", "regex", "serde", @@ -1550,7 +1550,7 @@ dependencies = [ "approx", "deer-desert", "erased-serde", - "error-stack 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "error-stack 0.4.1", "num-traits", "paste", "proptest", @@ -1567,7 +1567,7 @@ version = "0.0.0" dependencies = [ "bitvec", "deer", - "error-stack 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "error-stack 0.4.1", "num-traits", "serde", "serde_json", @@ -1579,7 +1579,7 @@ name = "deer-json" version = "0.0.0-reserved" dependencies = [ "deer", - "error-stack 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "error-stack 0.4.1", "justjson", "lexical", "memchr", @@ -1936,6 +1936,19 @@ dependencies = [ [[package]] name = "error-stack" version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "27a72baa257b5e0e2de241967bc5ee8f855d6072351042688621081d66b2a76b" +dependencies = [ + "anyhow", + "rustc_version", + "serde", + "spin 0.9.8", + "tracing-error", +] + +[[package]] +name = "error-stack" +version = "0.5.0" dependencies = [ "ansi-to-html", "anyhow", @@ -1959,24 +1972,11 @@ dependencies = [ "trybuild", ] -[[package]] -name = "error-stack" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27a72baa257b5e0e2de241967bc5ee8f855d6072351042688621081d66b2a76b" -dependencies = [ - "anyhow", - "rustc_version", - "serde", - "spin 0.9.8", - "tracing-error", -] - [[package]] name = "error-stack-macros" version = "0.0.0-reserved" dependencies = [ - "error-stack 0.4.1", + "error-stack 0.5.0", ] [[package]] @@ -2331,7 +2331,7 @@ dependencies = [ "criterion", "derive-where", "dotenv-flow", - "error-stack 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "error-stack 0.4.1", "futures", "graph-test-data", "graph-types", @@ -2370,7 +2370,7 @@ dependencies = [ "base64 0.22.1", "bytes", "codec", - "error-stack 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "error-stack 0.4.1", "futures", "graph", "graph-types", @@ -2431,7 +2431,7 @@ name = "graph-integration" version = "0.0.0" dependencies = [ "authorization", - "error-stack 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "error-stack 0.4.1", "futures", "graph", "graph-test-data", @@ -2461,7 +2461,7 @@ version = "0.0.0" dependencies = [ "bytes", "codec", - "error-stack 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "error-stack 0.4.1", "graph-test-data", "postgres-types", "pretty_assertions", @@ -2523,7 +2523,7 @@ dependencies = [ "bytes", "bytes-utils", "codec", - "error-stack 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "error-stack 0.4.1", "futures", "harpc-types", "harpc-wire-protocol", @@ -2555,7 +2555,7 @@ version = "0.0.0" dependencies = [ "bytes", "enumflags2", - "error-stack 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "error-stack 0.4.1", "expect-test", "harpc-types", "proptest", @@ -2573,7 +2573,7 @@ dependencies = [ "clap", "clap_complete", "codec", - "error-stack 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "error-stack 0.4.1", "futures", "graph", "graph-api", @@ -2602,7 +2602,7 @@ dependencies = [ name = "hash-status" version = "0.0.0" dependencies = [ - "error-stack 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "error-stack 0.4.1", "serde", "serde_json", ] @@ -2612,7 +2612,7 @@ name = "hash-tracing" version = "0.0.0" dependencies = [ "clap", - "error-stack 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "error-stack 0.4.1", "opentelemetry 0.23.0", "opentelemetry-otlp", "opentelemetry_sdk 0.23.0", @@ -5136,7 +5136,7 @@ dependencies = [ "clap", "clap_complete", "criterion", - "error-stack 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "error-stack 0.4.1", "inferno", "serde", "serde_json", @@ -6176,7 +6176,7 @@ dependencies = [ name = "temporal-client" version = "0.0.0" dependencies = [ - "error-stack 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "error-stack 0.4.1", "graph-types", "serde", "serde_json", @@ -6324,18 +6324,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.61" +version = "1.0.62" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c546c80d6be4bc6a00c0f01730c08df82eaa7a7a61f11d656526506112cc1709" +checksum = "f2675633b1499176c2dff06b0856a27976a8f9d436737b4cf4f312d4d91d8bbb" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.61" +version = "1.0.62" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" +checksum = "d20468752b09f49e909e55a5d338caa8bedf615594e9d80bc4c565d30faf798c" dependencies = [ "proc-macro2", "quote", @@ -6899,7 +6899,7 @@ dependencies = [ "codec", "console_error_panic_hook", "email_address", - "error-stack 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "error-stack 0.4.1", "graph-test-data", "iso8601-duration", "postgres-types", @@ -7116,7 +7116,7 @@ version = "0.0.0" dependencies = [ "chrono", "email_address", - "error-stack 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "error-stack 0.4.1", "futures", "graph-test-data", "graph-types", diff --git a/libs/error-stack/CHANGELOG.md b/libs/error-stack/CHANGELOG.md index 5d2929fd5a4..12a2a81693c 100644 --- a/libs/error-stack/CHANGELOG.md +++ b/libs/error-stack/CHANGELOG.md @@ -6,7 +6,7 @@ All notable changes to `error-stack` will be documented in this file. - Support for [`defmt`](https://defmt.ferrous-systems.com) -## 0.5.0 - Unreleased +## [0.5.0](https://github.com/hashintel/hash/tree/error-stack%400.5.0/libs/error-stack) - 2024-07-12 ### Features @@ -15,6 +15,7 @@ All notable changes to `error-stack` will be documented in this file. ### Breaking Changes - `Backtrace`s are not included in the `std` feature anymore. Instead, the `backtrace` feature is used which is enabled by default ([#4685](https://github.com/hashintel/hash/pull/4685)) +- Remove deprecated `IntoReport` ([#4706](https://github.com/hashintel/hash/pull/4706)) ## [0.4.1](https://github.com/hashintel/hash/tree/error-stack%400.4.1/libs/error-stack) - 2023-09-04 diff --git a/libs/error-stack/Cargo.toml b/libs/error-stack/Cargo.toml index ca672ba536b..4c6b2484dfd 100644 --- a/libs/error-stack/Cargo.toml +++ b/libs/error-stack/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "error-stack" -version = "0.4.1" +version = "0.5.0" authors = ["HASH"] edition = "2021" rust-version = "1.63.0" diff --git a/libs/error-stack/build.rs b/libs/error-stack/build.rs index 70657cb0848..0516216230c 100644 --- a/libs/error-stack/build.rs +++ b/libs/error-stack/build.rs @@ -21,4 +21,9 @@ fn main() { println!("cargo:warning=The `backtrace` feature requires Rust 1.65.0 or later."); exit(1); } + + println!("cargo:rustc-check-cfg=cfg(rust_1_81)"); + if trimmed_rustc_version >= Version::new(1, 81, 0) { + println!("cargo:rustc-cfg=rust_1_81"); + } } diff --git a/libs/error-stack/src/context.rs b/libs/error-stack/src/context.rs index 739a0d05446..d437b05e485 100644 --- a/libs/error-stack/src/context.rs +++ b/libs/error-stack/src/context.rs @@ -1,7 +1,12 @@ +#[cfg(any(feature = "std", rust_1_81))] use alloc::string::{String, ToString}; +#[cfg(rust_1_81)] +use core::error::Error; #[cfg(nightly)] use core::error::Request; -use core::{error::Error, fmt}; +use core::fmt; +#[cfg(all(feature = "std", not(rust_1_81)))] +use std::error::Error; use crate::Report; @@ -67,32 +72,38 @@ pub trait Context: fmt::Display + fmt::Debug + Send + Sync + 'static { /// This method only exists to avoid the requirement of specialization and to get the sources /// for `Error`. #[doc(hidden)] + #[cfg(any(feature = "std", rust_1_81))] fn __source(&self) -> Option<&(dyn Error + 'static)> { None } } /// Captures an error message as the context of a [`Report`]. +#[cfg(any(feature = "std", rust_1_81))] pub(crate) struct SourceContext(String); +#[cfg(any(feature = "std", rust_1_81))] impl SourceContext { pub(crate) fn from_error(value: &dyn Error) -> Self { Self(value.to_string()) } } +#[cfg(any(feature = "std", rust_1_81))] impl fmt::Debug for SourceContext { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Debug::fmt(&self.0, fmt) } } +#[cfg(any(feature = "std", rust_1_81))] impl fmt::Display for SourceContext { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Display::fmt(&self.0, fmt) } } +#[cfg(any(feature = "std", rust_1_81))] impl Context for SourceContext {} impl From for Report @@ -106,6 +117,7 @@ where } } +#[cfg(any(feature = "std", rust_1_81))] impl Context for C { #[cfg(nightly)] fn provide<'a>(&'a self, request: &mut Request<'a>) { diff --git a/libs/error-stack/src/error.rs b/libs/error-stack/src/error.rs index 83ec755b874..508968c9858 100644 --- a/libs/error-stack/src/error.rs +++ b/libs/error-stack/src/error.rs @@ -1,7 +1,11 @@ +#![cfg(any(feature = "std", rust_1_81))] + +#[cfg(rust_1_81)] +use core::error::Error; #[cfg(nightly)] -use core::error::{Error, Request}; +use core::error::Request; use core::fmt; -#[cfg(not(nightly))] +#[cfg(all(feature = "std", not(rust_1_81)))] use std::error::Error; use crate::Report; @@ -32,6 +36,7 @@ impl fmt::Display for ReportError { } } +#[cfg(any(feature = "std", rust_1_81))] impl Error for ReportError { #[cfg(nightly)] fn provide<'a>(&'a self, request: &mut Request<'a>) { diff --git a/libs/error-stack/src/lib.rs b/libs/error-stack/src/lib.rs index f768757f1c7..4c118910641 100644 --- a/libs/error-stack/src/lib.rs +++ b/libs/error-stack/src/lib.rs @@ -516,11 +516,7 @@ pub use self::{ result::Result, }; #[doc(inline)] -#[allow(deprecated)] -pub use self::{ - future::FutureExt, - result::{IntoReport, ResultExt}, -}; +pub use self::{future::FutureExt, result::ResultExt}; #[cfg(test)] #[allow(dead_code)] diff --git a/libs/error-stack/src/report.rs b/libs/error-stack/src/report.rs index ee8ea853e3d..03b6362fa9d 100644 --- a/libs/error-stack/src/report.rs +++ b/libs/error-stack/src/report.rs @@ -1,18 +1,23 @@ #[cfg_attr(feature = "std", allow(unused_imports))] use alloc::{boxed::Box, vec, vec::Vec}; -use core::{error::Error, fmt, marker::PhantomData, mem, panic::Location}; +#[cfg(rust_1_81)] +use core::error::Error; +use core::{fmt, marker::PhantomData, mem, panic::Location}; #[cfg(feature = "backtrace")] use std::backtrace::{Backtrace, BacktraceStatus}; +#[cfg(all(feature = "std", not(rust_1_81)))] +use std::error::Error; #[cfg(feature = "std")] use std::process::ExitCode; #[cfg(feature = "spantrace")] use tracing_error::{SpanTrace, SpanTraceStatus}; +#[cfg(any(feature = "std", rust_1_81))] +use crate::context::SourceContext; #[cfg(nightly)] use crate::iter::{RequestRef, RequestValue}; use crate::{ - context::SourceContext, iter::{Frames, FramesMut}, Context, Frame, }; @@ -263,6 +268,7 @@ impl Report { where C: Context, { + #[cfg(any(feature = "std", rust_1_81))] if let Some(mut current_source) = context.__source() { // The sources needs to be applied in reversed order, so we buffer them in a vector let mut sources = vec![SourceContext::from_error(current_source)]; @@ -281,11 +287,11 @@ impl Report { report = report.change_context(source); } // Finally, we add the new context passed to this function - report.change_context(context) - } else { - // We don't have any sources, directly create the `Report` from the context - Self::from_frame(Frame::from_context(context, Box::new([]))) + return report.change_context(context); } + + // We don't have any sources, directly create the `Report` from the context + Self::from_frame(Frame::from_context(context, Box::new([]))) } #[track_caller] @@ -651,6 +657,7 @@ impl Report { /// Converts this `Report` to an [`Error`]. #[must_use] + #[cfg(any(feature = "std", rust_1_81))] pub fn into_error(self) -> impl Error + Send + Sync + 'static where C: 'static, @@ -660,6 +667,7 @@ impl Report { /// Returns this `Report` as an [`Error`]. #[must_use] + #[cfg(any(feature = "std", rust_1_81))] pub fn as_error(&self) -> &(impl Error + Send + Sync + 'static) where C: 'static, @@ -668,24 +676,28 @@ impl Report { } } +#[cfg(any(feature = "std", rust_1_81))] impl From> for Box { fn from(report: Report) -> Self { Box::new(report.into_error()) } } +#[cfg(any(feature = "std", rust_1_81))] impl From> for Box { fn from(report: Report) -> Self { Box::new(report.into_error()) } } +#[cfg(any(feature = "std", rust_1_81))] impl From> for Box { fn from(report: Report) -> Self { Box::new(report.into_error()) } } +#[cfg(any(feature = "std", rust_1_81))] impl From> for Box { fn from(report: Report) -> Self { Box::new(report.into_error()) diff --git a/libs/error-stack/src/result.rs b/libs/error-stack/src/result.rs index f60d3609954..42cc2365a96 100644 --- a/libs/error-stack/src/result.rs +++ b/libs/error-stack/src/result.rs @@ -265,36 +265,3 @@ where } } } - -/// Extends [`Result`] to convert the [`Err`] variant to a [`Report`] -#[deprecated( - since = "0.4.0", - note = "Use `ResultExt` or `From` via `Result::map_err(Report::from)` instead" -)] -pub trait IntoReport: Sized { - /// Type of the [`Ok`] value in the [`Result`] - type Ok; - - /// Type of the resulting [`Err`] variant wrapped inside a [`Report`]. - type Err; - - /// Converts the [`Err`] variant of the [`Result`] to a [`Report`] - fn into_report(self) -> Result; -} - -#[allow(deprecated)] -impl IntoReport for core::result::Result -where - Report: From, -{ - type Err = E; - type Ok = T; - - #[track_caller] - fn into_report(self) -> Result { - match self { - Ok(value) => Ok(value), - Err(error) => Err(Report::from(error)), - } - } -} diff --git a/libs/error-stack/tests/ui/into_report.rs b/libs/error-stack/tests/ui/into_report.rs deleted file mode 100644 index 6c9f593acb8..00000000000 --- a/libs/error-stack/tests/ui/into_report.rs +++ /dev/null @@ -1,25 +0,0 @@ -#![allow(deprecated)] - -use core::fmt; - -use error_stack::{Context, IntoReport, Report}; - -#[derive(Debug)] -pub struct RootError; - -impl fmt::Display for RootError { - fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt.write_str("root error") - } -} - -impl Context for RootError {} - -fn main() { - let result = Err::<(), _>(RootError); - let _: Result<(), Report> = result.into_report(); - - let result = Err::<(), _>(Report::new(RootError)); - // Not allowed - let _ = result.into_report(); -} diff --git a/libs/error-stack/tests/ui/into_report.stderr b/libs/error-stack/tests/ui/into_report.stderr deleted file mode 100644 index 9fa766635aa..00000000000 --- a/libs/error-stack/tests/ui/into_report.stderr +++ /dev/null @@ -1,27 +0,0 @@ -error[E0599]: the method `into_report` exists for enum `Result<(), Report>`, but its trait bounds were not satisfied - --> tests/ui/into_report.rs:24:20 - | -24 | let _ = result.into_report(); - | ^^^^^^^^^^^ - | - ::: src/report.rs - | - | pub struct Report { - | -------------------- doesn't satisfy `_: From>` - | - ::: $RUST/core/src/result.rs - | - | pub enum Result { - | --------------------- doesn't satisfy `_: IntoReport` - | -note: there's an earlier shadowed binding `result` of type `Result<(), RootError>` that has method `into_report` available - --> tests/ui/into_report.rs:19:9 - | -19 | let result = Err::<(), _>(RootError); - | ^^^^^^ `result` of type `Result<(), RootError>` that has method `into_report` defined earlier here -... -22 | let result = Err::<(), _>(Report::new(RootError)); - | ------ earlier `result` shadowed here with type `Result<(), error_stack::Report>` - = note: the following trait bounds were not satisfied: - `error_stack::Report>: From>` - which is required by `Result<(), error_stack::Report>: IntoReport`