-
Notifications
You must be signed in to change notification settings - Fork 109
Open
Labels
area/libsRelates to first-party libraries/crates/packages (area)Relates to first-party libraries/crates/packages (area)area/libs > error-stackAffects the `error-stack` crate (library)Affects the `error-stack` crate (library)category/bugSomething isn't workingSomething isn't workinglang/rustPull requests that update Rust codePull requests that update Rust codepriority/2 mediumMedium priority: needs to be doneMedium priority: needs to be done
Description
Describe the bug
For a reason I haven't yet understood, ResultExt trait doesn't work on error_stack::Result (e.g. change_context is not found), although EyreReport seems to satisfy the Context trait.
However, it is possible to call Report::change_context on it without a problem.
To reproduce
use error_stack::{IntoReportCompat, ResultExt};
fn eyre_result() -> eyre::Result<()> {
Err(eyre::eyre!("Something happened"))
}
#[derive(Debug, thiserror::Error)]
#[error("my error occurred")]
struct MyError;
fn main() -> error_stack::Result<(), MyError> {
// doesn't compile
eyre_result()
.into_report()
.change_context(MyError)?;
// fine
eyre_result()
.into_report()
.map_err(|report| report.change_context(MyError))?;
Ok(())
}https://github.com/0x009922/error-stack-eyre-compat-issue
Expected behavior
Expected .into_report().change_context(...) to work
Rust compiler
1.76.0 (07dca489a 2024-02-04)
Host
aarch64-apple-darwin
Target
aarch64-apple-darwin
Version
0.4.1
Features
default, eyre
Additional context
Compiler error:
error[E0599]: no method named `change_context` found for enum `Result` in the current scope
--> src/main.rs:15:10
|
13 | / eyre_result()
14 | | .into_report()
15 | | .change_context(MyError)?;
| | -^^^^^^^^^^^^^^ method not found in `Result<(), Report>`
| |_________|
|
|
note: the method `change_context` exists on the type `error_stack::Report`
--> [redacted]/error-stack-0.4.1/src/report.rs:462:5
|
462 | / pub fn change_context(mut self, context: T) -> Report
463 | | where
464 | | T: Context,
| |___________________^
help: use the `?` operator to extract the `error_stack::Report` value, propagating a `Result::Err` value to the caller
|
14 | .into_report()?
| +
Metadata
Metadata
Assignees
Labels
area/libsRelates to first-party libraries/crates/packages (area)Relates to first-party libraries/crates/packages (area)area/libs > error-stackAffects the `error-stack` crate (library)Affects the `error-stack` crate (library)category/bugSomething isn't workingSomething isn't workinglang/rustPull requests that update Rust codePull requests that update Rust codepriority/2 mediumMedium priority: needs to be doneMedium priority: needs to be done