Skip to content

Commit

Permalink
Rename ErrReport to Report (#9)
Browse files Browse the repository at this point in the history
* Rename ErrReport to Report

* bump versions to prep for a release
  • Loading branch information
yaahc authored Apr 13, 2020
1 parent 6b601f8 commit e3bf56e
Show file tree
Hide file tree
Showing 16 changed files with 154 additions and 154 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "eyre"
version = "0.3.7" # remember to update html_root_url
version = "0.3.8" # remember to update html_root_url
authors = ["David Tolnay <[email protected]>", "Jane Lusby <[email protected]>"]
edition = "2018"
license = "MIT OR Apache-2.0"
Expand Down
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Eyre
[![Latest Version](https://img.shields.io/crates/v/eyre.svg)](https://crates.io/crates/eyre)
[![Rust Documentation](https://img.shields.io/badge/api-rustdoc-blue.svg)](https://docs.rs/eyre)

This library provides [`eyre::ErrReport`][ErrReport], a trait object based
This library provides [`eyre::Report`][Report], a trait object based
error handling type for easy idiomatic error handling and reporting in Rust
applications.

Expand All @@ -31,7 +31,7 @@ The main changes this crate brings to anyhow are
describing it as an error type in its own right. What is and isn't an error
is a fuzzy concept, for the purposes of this crate though errors are types
that implement `std::error::Error`, and you'll notice that this trait
implementation is conspicuously absent on `ErrReport`. Instead it contains
implementation is conspicuously absent on `Report`. Instead it contains
errors that it masqerades as, and provides helpers for creating new errors to
wrap those errors and for displaying those chains of errors, and the included
context, to the end user. The goal is to make it obvious that this type is
Expand All @@ -41,7 +41,7 @@ The main changes this crate brings to anyhow are
that it is unrelated to the [`eyre::EyreContext`] trait and member, and is
only for inserting new errors into the chain of errors.
* Addition of new context helpers `member_ref`/`member_mut` on `EyreContext`
and `context`/`context_mut` on `ErrReport` for working with the custom
and `context`/`context_mut` on `Report` for working with the custom
context and extracting forms of context based on their type independent of
the type of the custom context.

Expand Down Expand Up @@ -83,7 +83,7 @@ fn default(error: &(dyn StdError + 'static)) -> Self {
-> fmt Result` and optionally `display` - For formatting the entire error
chain and the user provided context.

When overriding the context it no longer makes sense for `eyre::ErrReport` to
When overriding the context it no longer makes sense for `eyre::Report` to
provide the `Display` and `Debug` implementations for the user, becase we
cannot predict what forms of context you will need to display along side your
chain of errors. Instead we forward the implementations of `Display` and
Expand All @@ -108,11 +108,11 @@ implementations of `display` and `debug` on `eyre::DefaultContext`
getting a mutable reference in the same way.

This method is like a flexible version of the `fn backtrace(&self)` method on
the `Error` trait. The main `ErrReport` type provides versions of these methods
the `Error` trait. The main `Report` type provides versions of these methods
that use type inference to get the typeID that should be used by inner trait fn
to pick a member to return.

**Note**: The `backtrace()` fn on `ErrReport` relies on the implementation of
**Note**: The `backtrace()` fn on `Report` relies on the implementation of
this function to get the backtrace from the user provided context if one
exists. If you wish your type to guaruntee that it captures a backtrace for any
error it wraps you **must** implement `member_ref` and provide a path to return
Expand All @@ -135,17 +135,17 @@ application by defining a type alias.


```rust
type ErrReport = eyre::ErrReport<MyContext>;
type Report = eyre::Report<MyContext>;

// And optionally...
type Result<T, E = eyre::ErrReport<MyContext>> = core::result::Result<T, E>;
type Result<T, E = eyre::Report<MyContext>> = core::result::Result<T, E>;
```

<br>

## Details

- Use `Result<T, eyre::ErrReport>`, or equivalently `eyre::Result<T>`, as the
- Use `Result<T, eyre::Report>`, or equivalently `eyre::Result<T>`, as the
return type of any fallible function.

Within the function, use `?` to easily propagate any error that implements the
Expand Down Expand Up @@ -224,7 +224,7 @@ type Result<T, E = eyre::ErrReport<MyContext>> = core::result::Result<T, E>;
```

- One-off error messages can be constructed using the `eyre!` macro, which
supports string interpolation and produces an `eyre::ErrReport`.
supports string interpolation and produces an `eyre::Report`.

```rust
return Err(eyre!("Missing attribute: {}", missing));
Expand All @@ -249,14 +249,14 @@ eyre = { version = "0.3", default-features = false }

Since the `?`-based error conversions would normally rely on the
`std::error::Error` trait which is only available through std, no_std mode will
require an explicit `.map_err(ErrReport::msg)` when working with a non-Eyre error
require an explicit `.map_err(Report::msg)` when working with a non-Eyre error
type inside a function that returns Eyre's error type.

<br>

## Comparison to failure

The `eyre::ErrReport` type works something like `failure::Error`, but unlike
The `eyre::Report` type works something like `failure::Error`, but unlike
failure ours is built around the standard library's `std::error::Error` trait
rather than a separate trait `failure::Fail`. The standard library has adopted
the necessary improvements for this to be possible as part of [RFC 2504].
Expand Down Expand Up @@ -298,9 +298,9 @@ via your return type or a type annotation.
let val = get_optional_val.ok_or_else(|| eyre!("failed to get value)).unwrap();

// Works
let val: ErrReport = get_optional_val.ok_or_else(|| eyre!("failed to get value)).unwrap();
let val: Report = get_optional_val.ok_or_else(|| eyre!("failed to get value)).unwrap();
```
[ErrReport]: https://docs.rs/eyre/*/eyre/struct.ErrReport.html
[Report]: https://docs.rs/eyre/*/eyre/struct.Report.html
[`eyre::EyreContext`]: https://docs.rs/eyre/*/eyre/trait.EyreContext.html
[`eyre::WrapErr`]: https://docs.rs/eyre/*/eyre/trait.WrapErr.html
[`anyhow::Context`]: https://docs.rs/anyhow/*/anyhow/trait.Context.html
Expand Down
18 changes: 9 additions & 9 deletions src/context.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::error::ContextError;
use crate::{ErrReport, EyreContext, StdError, WrapErr};
use crate::{EyreContext, Report, StdError, WrapErr};
use core::fmt::{self, Debug, Display, Write};

#[cfg(backtrace)]
Expand All @@ -12,7 +12,7 @@ mod ext {
where
C: EyreContext,
{
fn ext_report<D>(self, msg: D) -> ErrReport<C>
fn ext_report<D>(self, msg: D) -> Report<C>
where
D: Display + Send + Sync + 'static;
}
Expand All @@ -23,19 +23,19 @@ mod ext {
C: EyreContext,
E: std::error::Error + Send + Sync + 'static,
{
fn ext_report<D>(self, msg: D) -> ErrReport<C>
fn ext_report<D>(self, msg: D) -> Report<C>
where
D: Display + Send + Sync + 'static,
{
ErrReport::from_msg(msg, self)
Report::from_msg(msg, self)
}
}

impl<C> StdError<C> for ErrReport<C>
impl<C> StdError<C> for Report<C>
where
C: EyreContext,
{
fn ext_report<D>(self, msg: D) -> ErrReport<C>
fn ext_report<D>(self, msg: D) -> Report<C>
where
D: Display + Send + Sync + 'static,
{
Expand All @@ -49,14 +49,14 @@ where
C: EyreContext,
E: ext::StdError<C> + Send + Sync + 'static,
{
fn wrap_err<D>(self, msg: D) -> Result<T, ErrReport<C>>
fn wrap_err<D>(self, msg: D) -> Result<T, Report<C>>
where
D: Display + Send + Sync + 'static,
{
self.map_err(|error| error.ext_report(msg))
}

fn wrap_err_with<D, F>(self, msg: F) -> Result<T, ErrReport<C>>
fn wrap_err_with<D, F>(self, msg: F) -> Result<T, Report<C>>
where
D: Display + Send + Sync + 'static,
F: FnOnce() -> D,
Expand Down Expand Up @@ -102,7 +102,7 @@ where
}
}

impl<D, C> StdError for ContextError<D, ErrReport<C>>
impl<D, C> StdError for ContextError<D, Report<C>>
where
C: EyreContext,
D: Display,
Expand Down
Loading

0 comments on commit e3bf56e

Please sign in to comment.