From 7912040f6f18e4569c33e04dfe6584fa42754899 Mon Sep 17 00:00:00 2001 From: Jane Lusby Date: Sun, 17 May 2020 09:00:21 -0700 Subject: [PATCH 1/4] Update testing --- .github/workflows/ci.yml | 52 +++++++++++++++++++++++++++++++++++----- Cargo.toml | 2 +- tests/test_boxed.rs | 15 ++++++++++++ 3 files changed, 62 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6b3c3f8..058f962 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,8 @@ -on: [push, pull_request] +on: + push: + branches: + - master + pull_request: {} name: Continuous integration @@ -20,14 +24,37 @@ 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 + - uses: actions-rs/cargo@v1 + with: + command: test + args: --no-default-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 @@ -37,10 +64,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 diff --git a/Cargo.toml b/Cargo.toml index 153afb1..1b0ac52 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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"] diff --git a/tests/test_boxed.rs b/tests/test_boxed.rs index 6a6f5a0..9e87dfa 100644 --- a/tests/test_boxed.rs +++ b/tests/test_boxed.rs @@ -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::::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() + ); +} From cbda7894e93c95a77276833dfe49cd588e72f9ae Mon Sep 17 00:00:00 2001 From: Jane Lusby Date: Sun, 17 May 2020 09:37:50 -0700 Subject: [PATCH 2/4] dont bother testing no_std yet ... --- .github/workflows/ci.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 058f962..879ee8f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -40,10 +40,6 @@ jobs: with: command: test args: --all-features - - uses: actions-rs/cargo@v1 - with: - command: test - args: --no-default-features test-versions: name: Test Suite From b960f062c66a66114f11e9d8b0204c809e626c1e Mon Sep 17 00:00:00 2001 From: Jane Lusby Date: Sun, 17 May 2020 10:05:22 -0700 Subject: [PATCH 3/4] bump version for new release with fixed indenter --- Cargo.toml | 2 +- src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1b0ac52..4637618 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 ", "Jane Lusby "] edition = "2018" license = "MIT OR Apache-2.0" diff --git a/src/lib.rs b/src/lib.rs index a014a56..53bb51a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -272,7 +272,7 @@ //! [`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")] +#![doc(html_root_url = "https://docs.rs/eyre/0.4.2")] #![warn( missing_debug_implementations, missing_docs, From 3658881052ee832e784759ba67755adafa0cce1a Mon Sep 17 00:00:00 2001 From: Jane Lusby Date: Sun, 17 May 2020 10:27:03 -0700 Subject: [PATCH 4/4] add documentation about custom context crates --- README.md | 32 ++++++++++++++++++++++++++++---- src/lib.rs | 37 ++++++++++++++++++++++++++++++++----- 2 files changed, 60 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 84f7959..faefd8a 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/src/lib.rs b/src/lib.rs index 53bb51a..425a06e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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`, or equivalently `eyre::Result`, as @@ -265,13 +286,19 @@ //! 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 +//! [`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,