Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update testing #19

Merged
merged 4 commits into from
May 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 42 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
on: [push, pull_request]
on:
push:
branches:
- master
pull_request: {}

name: Continuous integration

Expand All @@ -20,14 +24,33 @@ jobs:
with:
command: check

test:
test-features:
name: Test Suite
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- uses: actions-rs/cargo@v1
with:
command: test
- uses: actions-rs/cargo@v1
with:
command: test
args: --all-features

test-versions:
name: Test Suite
runs-on: ubuntu-latest
strategy:
matrix:
rust:
- stable
- beta
- nightly
- 1.39.0
steps:
- uses: actions/checkout@v1
- uses: actions-rs/toolchain@v1
Expand All @@ -37,10 +60,23 @@ jobs:
- uses: actions-rs/cargo@v1
with:
command: test
# - uses: actions-rs/cargo@v1
# with:
# command: test
# args: --no-default-features

test-os:
name: Test Suite
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
steps:
- uses: actions/checkout@v1
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true
- uses: actions-rs/cargo@v1
with:
command: test

fmt:
name: Rustfmt
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "eyre"
version = "0.4.1" # remember to update html_root_url
version = "0.4.2" # remember to update html_root_url
authors = ["David Tolnay <[email protected]>", "Jane Lusby <[email protected]>"]
edition = "2018"
license = "MIT OR Apache-2.0"
Expand All @@ -23,7 +23,7 @@ backtrace = "0.3.46"
anyhow = "1.0.28"

[dependencies]
indenter = "0.2.0"
indenter = "0.3.0"

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]
Expand Down
32 changes: 28 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,28 @@ applications.

This crate is a fork of [`anyhow`] by @dtolnay with a support for customized
`Reports`. For more details on customization checkout the docs on
[`eyre::EyreContext`]. For an example on how to implement a custom context
check out [`stable-eyre`] which implements a minimal custom context for
capturing backtraces on stable.
[`eyre::EyreContext`].

## Custom Contexts

The heart of this crate is it's ability to swap out the Context type to change
what information is carried alongside errors and how the end report is
formatted. This crate is meant to be used alongside companion crates that
customize its behavior. Below is a list of known custom context crates and
short summaries of what features they provide.

- [`stable-eyre`]: Switches the backtrace type from `std`'s to `backtrace-rs`'s
so that it can be captured on stable. The report format is identical to
`DefaultContext`'s report format.
- [`color-eyre`]: Captures a `backtrace::Backtrace` and a
`tracing_error::SpanTrace`. Provides a `Help` trait for attaching warnings
and suggestions to error reports. The end report is then pretty printed with
the help of [`color-backtrace`], [`color-spantrace`], and `ansi_term`. Check
out the README on [`color-eyre`] for screenshots of the report format.
- [`simple-eyre`]: A minimal `EyreContext` that captures no additional
information, for when you do not wish to capture `Backtrace`s with errors.
- [`jane-eyre`]: A custom context type that exists purely for the pun.
Currently just re-exports `color-eyre`.

## Details

Expand Down Expand Up @@ -229,7 +248,12 @@ implements `context` for options which you can import to make existing
[`anyhow::Context`]: https://docs.rs/anyhow/*/anyhow/trait.Context.html
[`anyhow`]: https://github.com/dtolnay/anyhow
[`tracing_error::SpanTrace`]: https://docs.rs/tracing-error/*/tracing_error/struct.SpanTrace.html
[`stable-eyre`]: https://docs.rs/stable-eyre
[`stable-eyre`]: https://github.com/yaahc/stable-eyre
[`color-eyre`]: https://github.com/yaahc/color-eyre
[`jane-eyre`]: https://github.com/yaahc/jane-eyre
[`simple-eyre`]: https://github.com/yaahc/simple-eyre
[`color-spantrace`]: https://github.com/yaahc/color-spantrace
[`color-backtrace`]: https://github.com/athre0z/color-backtrace
[actions-badge]: https://github.com/yaahc/eyre/workflows/Continuous%20integration/badge.svg
[actions-url]: https://github.com/yaahc/eyre/actions?query=workflow%3A%22Continuous+integration%22

Expand Down
39 changes: 33 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,36 @@
//! This library provides [`eyre::Report`][Report], a trait object based error
//! type for easy idiomatic error handling in Rust applications.
//!
//! This crate is a fork of [`anyhow`] by @dtolnay with a support for customized `Reports`. For
//! more details on customization checkout the docs on [`eyre::EyreContext`]. For an example on how
//! to implement a custom context check out [`stable-eyre`] which implements a minimal custom
//! context for capturing backtraces on stable.
//! This crate is a fork of [`anyhow`] by @dtolnay with a support for customized
//! `Reports`. For more details on customization checkout the docs on
//! [`eyre::EyreContext`].
//!
//! ```toml
//! [dependencies]
//! eyre = "0.4"
//! ```
//!
//! ## Custom Contexts
//!
//! The heart of this crate is it's ability to swap out the Context type to change
//! what information is carried alongside errors and how the end report is
//! formatted. This crate is meant to be used alongside companion crates that
//! customize its behavior. Below is a list of known custom context crates and
//! short summaries of what features they provide.
//!
//! - [`stable-eyre`]: Switches the backtrace type from `std`'s to `backtrace-rs`'s
//! so that it can be captured on stable. The report format is identical to
//! `DefaultContext`'s report format.
//! - [`color-eyre`]: Captures a `backtrace::Backtrace` and a
//! `tracing_error::SpanTrace`. Provides a `Help` trait for attaching warnings
//! and suggestions to error reports. The end report is then pretty printed with
//! the help of [`color-backtrace`], [`color-spantrace`], and `ansi_term`. Check
//! out the README on [`color-eyre`] for screenshots of the report format.
//! - [`simple-eyre`]: A minimal `EyreContext` that captures no additional
//! information, for when you do not wish to capture `Backtrace`s with errors.
//! - [`jane-eyre`]: A custom context type that exists purely for the pun.
//! Currently just re-exports `color-eyre`.
//!
//! ## Details
//!
//! - Use `Result<T, eyre::Report>`, or equivalently `eyre::Result<T>`, as
Expand Down Expand Up @@ -265,14 +286,20 @@
//! However, to help with porting we do provide a `ContextCompat` trait which
//! implements `context` for options which you can import to make existing
//! `.context` calls compile.
//!
//! [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
//! [`anyhow`]: https://github.com/dtolnay/anyhow
//! [`tracing_error::SpanTrace`]: https://docs.rs/tracing-error/*/tracing_error/struct.SpanTrace.html
//! [`stable_eyre`]: https://docs.rs/stable-eyre
#![doc(html_root_url = "https://docs.rs/eyre/0.4.1")]
//! [`stable-eyre`]: https://github.com/yaahc/stable-eyre
//! [`color-eyre`]: https://github.com/yaahc/color-eyre
//! [`jane-eyre`]: https://github.com/yaahc/jane-eyre
//! [`simple-eyre`]: https://github.com/yaahc/simple-eyre
//! [`color-spantrace`]: https://github.com/yaahc/color-spantrace
//! [`color-backtrace`]: https://github.com/athre0z/color-backtrace
#![doc(html_root_url = "https://docs.rs/eyre/0.4.2")]
#![warn(
missing_debug_implementations,
missing_docs,
Expand Down
15 changes: 15 additions & 0 deletions tests/test_boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,18 @@ fn test_boxed_eyre() {
let error = eyre!(error);
assert_eq!("oh no!", error.source().unwrap().to_string());
}

#[test]
fn test_boxed_sources() {
let error = MyError {
source: io::Error::new(io::ErrorKind::Other, "oh no!"),
};
let error = Box::<dyn StdError + Send + Sync>::from(error);
let error: Report = eyre!(error).wrap_err("it failed");
assert_eq!("it failed", error.to_string());
assert_eq!("outer", error.source().unwrap().to_string());
assert_eq!(
"oh no!",
error.source().unwrap().source().unwrap().to_string()
);
}