Skip to content

Make Report compatible with std::error::Error based types #1746

@mayabyte

Description

@mayabyte

Related Problem

Let's say I have a library crate that uses error-stack for all its errors, and a pre-existing user-facing program that wants to use this library but doesn't want to do a big-bang migration of all its own error handling to use error-stack and may not ever care to - let's say it just uses Box<dyn Error> for all its errors.

Integrating the library's error types into the application is currently very clumsy and weird, requiring us to either pull the Contexts out of the Reports manually, stringify the errors, or some other tedious and undesirable pattern.

Proposed Solution

Other error handling libraries provide some conversion options for integrating with std Error that would solve this issue for error-stack. By way of example, eyre has the following:

  • impl AsRef<dyn Error + 'static> for Report
  • impl Deref<Target = dyn Error + Send + Sync + 'static> for Report
  • impl From<Report> for Box<dyn Error + 'static>

Alternatives

One possible alternative is implementing Error directly on Report. I can't tell whether this is deliberately being avoided, but neither eyre or anyhow do this for their error types so I assume there's a good reason not to choose this option.

Additional context

No response

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions