Skip to content

Report<E> is not compatible with std::error::Error #2886

@Tohman21

Description

@Tohman21

Related Problem

Hello! I ran into a problem, which is better to show with example:

struct Foo;

impl<V> Foo for SomeTrait<V>
  where
    V: TryInto<Vec<u8>>,
   <V as TryInto<Vec<u8>>>::Error: error_stack::Context,
{
  fn do_stuff(&self, value: V) -> error_stack::Result<(), MyError> {
    ...
    let my_vec: Vec<u8> = value.try_into().into_report().change_context(MyError);
    ...
  }
}

struct Bar;

impl TryInto<Vec<u8>> for Bar {
  type Error = error_stack::Report<TransformError>;

  fn try_into(self) -> Result<Vec<u8>, Self::Error> {
    /// Some serialization
  }
}

fn main() {
  let foo = Foo;
  let bar = Bar;
  let baz = "baz".to_owned();

  foo.do_stuff(baz); // Good
  foo.do_stuff(bar); // Error. The trait `StdError` is not implemented for `error_stack::Report<TransformationError>`
}

I have implementation of SomeTrait that requires TryInto<Vec<u8>>::Error implement error_stack::Context. But Report is not impl Context and is not impl Error.

Proposed Solution

Implement Error for Report:

impl<E> std:error::Error for Report<E> {}

It's simple and allows to write more abstract code. In other words Report will compatible with Errors

Alternatives

No response

Additional context

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions