Skip to content
This repository was archived by the owner on Aug 16, 2021. It is now read-only.
This repository was archived by the owner on Aug 16, 2021. It is now read-only.

Towards 0.2 and Beyond #287

Open
Open
@davidbarsky

Description

@davidbarsky

With most of RFC 2504 being implemented in stable, I wanted to share my idea of how Failure should evolve towards. For preserving context, I'll briefly re-iterate what RFC 2504 entails:

  • Error::cause is being replaced by Error::source in Rust 1.33, which supports downcasting of inner errors.
  • std::error::Error requires a Display and Debug, which provides a string-based representation of the error.
  • std provides a Backtrace module, which provides a minimal API for just printing a backtrace for end-users. This is not implemented yet, but @mitsuhiko indicated on December 28th, 2018 that he's working on the Backtrace implementation for std 1.

As @withoutboats indicated in RFC 2504, the Fail trait in Failure would become an extension trait to std:error::Error along the lines of:

trait ErrorExt: Error + Send + Sync + 'static {
    // various provided helper methods
}

The Failure crate would then provide a derive for the standard library's error akin to:

#[derive(Debug, Display, Error)]
#[display = "My display message."]
struct MyError {
    #[error(source)]
    underlying: std::io::Error,
    backtrace: Backtrace,
}

This new derive will be introduced in Failure 0.2. The corresponding derive of Fail can be removed with the release of 0.2, or more conservatively, marked as deprecated and removed entirely in Failure 0.3. The release of Failure 0.2 will come with a corresponding minimum Rust version bump to at least 1.31.

Additionally, while the following are not strictly bound to the release of Failure 0.2, we can also provide:

  • Additional convenience macros and methods for chaining errors.
  • More documentation and examples around different error-handling strategies.

Additionally, with Rust's increasing use in the network services space, a pain point that's emerged is best practices around error reporting to instrumentation systems. While the type_name intrinsic would be a great solution for this problem , it's currently nightly-only and blocked on specialization. Failure could patch this gap by introducing an associated const ERROR_TYPE: &'static str to ErrorExt for error-reporting purposes. This const can subsequently be removed and deprecated once specialization is available.

Feedback on this proposal is welcome and encouraged.


[1]: See the rust-lang Discord, the general channel. Relevant conversation reproduced below:

i was actually (sadly not on the machine i'm on holidays with right now) working on trying to make a patch for rust core that provides a backtrace api
that's the missing piece right now to have stdlib provide what failure needs

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions