diff --git a/Cargo.toml b/Cargo.toml index b58a509..9f1a1fc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,8 @@ members = [ "color-eyre", "color-spantrace", - "eyre" + "eyre", + "simple-eyre", ] [workspace.package] @@ -21,4 +22,3 @@ owo-colors = "3.2.0" [profile.dev.package.backtrace] opt-level = 3 - diff --git a/color-eyre/.github/workflows/ci.yml b/color-eyre/.github/workflows/ci.yml index 23ad9a0..2cf9ce8 100644 --- a/color-eyre/.github/workflows/ci.yml +++ b/color-eyre/.github/workflows/ci.yml @@ -7,23 +7,6 @@ on: name: Continuous integration jobs: - check: - name: Check - runs-on: ubuntu-latest - strategy: - matrix: - rust: - - stable - steps: - - uses: actions/checkout@v1 - - uses: actions-rs/toolchain@v1 - with: - toolchain: ${{ matrix.rust }} - override: true - - uses: actions-rs/cargo@v1 - with: - command: check - test-features: name: Test Features runs-on: ubuntu-latest @@ -78,58 +61,3 @@ jobs: - name: run wasm tests run: wasm-pack test --node if: ${{ matrix.target == 'wasm32-unknown-unknown' }} - - test-os: - name: Test Operating Systems - 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 - runs-on: ubuntu-latest - strategy: - matrix: - rust: - - stable - steps: - - uses: actions/checkout@v1 - - uses: actions-rs/toolchain@v1 - with: - toolchain: ${{ matrix.rust }} - override: true - - run: rustup component add rustfmt - - uses: actions-rs/cargo@v1 - with: - command: fmt - args: --all -- --check - - clippy: - name: Clippy - runs-on: ubuntu-latest - strategy: - matrix: - rust: - - stable - steps: - - uses: actions/checkout@v1 - - uses: actions-rs/toolchain@v1 - with: - toolchain: ${{ matrix.rust }} - override: true - - run: rustup component add clippy - - uses: actions-rs/cargo@v1 - with: - command: clippy - args: -- -D warnings diff --git a/color-eyre/Cargo.toml b/color-eyre/Cargo.toml index 9f325ec..95865ad 100644 --- a/color-eyre/Cargo.toml +++ b/color-eyre/Cargo.toml @@ -37,6 +37,10 @@ ansi-parser = "0.8.0" [target.'cfg(target_arch = "wasm32")'.dev-dependencies] wasm-bindgen-test = "0.3.15" +[[example]] +name = "color-eyre-usage" +path = "examples/usage.rs" + [package.metadata.docs.rs] all-features = true rustdoc-args = ["--cfg", "docsrs"] @@ -47,37 +51,27 @@ dev-version = false [[package.metadata.release.pre-release-replacements]] file = "CHANGELOG.md" search = "Unreleased" -replace="{{version}}" +replace = "{{version}}" [[package.metadata.release.pre-release-replacements]] -file = "src/lib.rs" -search = "#!\\[doc\\(html_root_url.*" -replace = "#![doc(html_root_url = \"https://docs.rs/{{crate_name}}/{{version}}\")]" -exactly = 1 +file = "CHANGELOG.md" +search = "ReleaseDate" +replace = "{{date}}" [[package.metadata.release.pre-release-replacements]] file = "CHANGELOG.md" -search = "\\.\\.\\.HEAD" -replace="...{{tag_name}}" +search = "" +replace = "\n\n## [Unreleased] - ReleaseDate" exactly = 1 [[package.metadata.release.pre-release-replacements]] file = "CHANGELOG.md" -search = "ReleaseDate" -replace="{{date}}" - -[[package.metadata.release.pre-release-replacements]] -file="CHANGELOG.md" -search="" -replace="\n\n## [Unreleased] - ReleaseDate" -exactly=1 +search = "\\.\\.\\.HEAD" +replace = "...{{tag_name}}" +exactly = 1 [[package.metadata.release.pre-release-replacements]] -file="CHANGELOG.md" -search="" -replace="\n[Unreleased]: https://github.com/eyre-rs/{{crate_name}}/compare/{{tag_name}}...HEAD" -exactly=1 - -[[example]] -name = "color-eyre-usage" -path = "examples/usage.rs" +file = "CHANGELOG.md" +search = "" +replace = "\n[Unreleased]: https://github.com/eyre-rs/{{crate_name}}/compare/{{tag_name}}...HEAD" +exactly = 1 diff --git a/color-eyre/src/config.rs b/color-eyre/src/config.rs index 22b4e60..3f14a6e 100644 --- a/color-eyre/src/config.rs +++ b/color-eyre/src/config.rs @@ -578,7 +578,6 @@ impl HookBuilder { /// .unwrap(); /// ``` #[cfg(feature = "issue-url")] - #[cfg_attr(docsrs, doc(cfg(feature = "issue-url")))] pub fn issue_url(mut self, url: S) -> Self { self.issue_url = Some(url.to_string()); self @@ -598,7 +597,6 @@ impl HookBuilder { /// .unwrap(); /// ``` #[cfg(feature = "issue-url")] - #[cfg_attr(docsrs, doc(cfg(feature = "issue-url")))] pub fn add_issue_metadata(mut self, key: K, value: V) -> Self where K: Display, @@ -634,7 +632,6 @@ impl HookBuilder { /// .unwrap(); /// #[cfg(feature = "issue-url")] - #[cfg_attr(docsrs, doc(cfg(feature = "issue-url")))] pub fn issue_filter(mut self, predicate: F) -> Self where F: Fn(crate::ErrorKind<'_>) -> bool + Send + Sync + 'static, @@ -661,7 +658,6 @@ impl HookBuilder { /// /// This will not disable the location section in a panic message. #[cfg(feature = "track-caller")] - #[cfg_attr(docsrs, doc(cfg(feature = "track-caller")))] pub fn display_location_section(mut self, cond: bool) -> Self { self.display_location_section = cond; self @@ -1217,5 +1213,4 @@ pub type FilterCallback = dyn Fn(&mut Vec<&Frame>) + Send + Sync + 'static; /// Callback for filtering issue url generation in error reports #[cfg(feature = "issue-url")] -#[cfg_attr(docsrs, doc(cfg(feature = "issue-url")))] pub type IssueFilterCallback = dyn Fn(crate::ErrorKind<'_>) -> bool + Send + Sync + 'static; diff --git a/color-eyre/src/handler.rs b/color-eyre/src/handler.rs index 80c1417..1f29cb3 100644 --- a/color-eyre/src/handler.rs +++ b/color-eyre/src/handler.rs @@ -24,7 +24,6 @@ impl Handler { /// Return a reference to the captured `SpanTrace` type #[cfg(feature = "capture-spantrace")] - #[cfg_attr(docsrs, doc(cfg(feature = "capture-spantrace")))] pub fn span_trace(&self) -> Option<&SpanTrace> { self.span_trace.as_ref() } diff --git a/color-eyre/src/lib.rs b/color-eyre/src/lib.rs index 2664cad..54d3529 100644 --- a/color-eyre/src/lib.rs +++ b/color-eyre/src/lib.rs @@ -325,20 +325,23 @@ //! [`eyre::EyreHandler`]: https://docs.rs/eyre/*/eyre/trait.EyreHandler.html //! [`backtrace::Backtrace`]: https://docs.rs/backtrace/*/backtrace/struct.Backtrace.html //! [`tracing_error::SpanTrace`]: https://docs.rs/tracing-error/*/tracing_error/struct.SpanTrace.html -//! [`color-spantrace`]: https://github.com/yaahc/color-spantrace +//! [`color-spantrace`]: https://docs.rs/color-spantrace //! [`Section`]: https://docs.rs/color-eyre/*/color_eyre/trait.Section.html //! [`eyre::Report`]: https://docs.rs/eyre/*/eyre/struct.Report.html //! [`eyre::Result`]: https://docs.rs/eyre/*/eyre/type.Result.html //! [`Handler`]: https://docs.rs/color-eyre/*/color_eyre/struct.Handler.html -//! [`examples/usage.rs`]: https://github.com/yaahc/color-eyre/blob/master/examples/usage.rs -//! [`examples/custom_filter.rs`]: https://github.com/yaahc/color-eyre/blob/master/examples/custom_filter.rs -//! [`examples/custom_section.rs`]: https://github.com/yaahc/color-eyre/blob/master/examples/custom_section.rs -//! [`examples/multiple_errors.rs`]: https://github.com/yaahc/color-eyre/blob/master/examples/multiple_errors.rs -#![doc(html_root_url = "https://docs.rs/color-eyre/0.6.2")] -#![cfg_attr(docsrs, feature(doc_cfg))] +//! [`examples/usage.rs`]: https://github.com/eyre-rs/eyre/blob/master/color-eyre/examples/usage.rs +//! [`examples/custom_filter.rs`]: https://github.com/eyre-rs/eyre/blob/master/color-eyre/examples/custom_filter.rs +//! [`examples/custom_section.rs`]: https://github.com/eyre-rs/eyre/blob/master/color-eyre/examples/custom_section.rs +//! [`examples/multiple_errors.rs`]: https://github.com/eyre-rs/eyre/blob/master/color-eyre/examples/multiple_errors.rs +#![cfg_attr( + nightly, + feature(rustdoc_missing_doc_code_examples), + warn(rustdoc::missing_doc_code_examples) +)] +#![cfg_attr(docsrs, feature(doc_auto_cfg))] #![warn( missing_docs, - rustdoc::missing_doc_code_examples, rust_2018_idioms, unreachable_pub, bad_style, @@ -349,13 +352,13 @@ overflowing_literals, path_statements, patterns_in_fns_without_body, + unconditional_recursion, unused, unused_allocation, unused_comparisons, unused_parens, while_true )] -#![allow(clippy::try_err)] use std::sync::Arc; @@ -418,7 +421,6 @@ pub struct Handler { /// The kind of type erased error being reported #[cfg(feature = "issue-url")] -#[cfg_attr(docsrs, doc(cfg(feature = "issue-url")))] pub enum ErrorKind<'a> { /// A non recoverable error aka `panic!` NonRecoverable(&'a dyn std::any::Any), diff --git a/color-spantrace/.gitignore b/color-spantrace/.gitignore deleted file mode 100644 index 96ef6c0..0000000 --- a/color-spantrace/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/target -Cargo.lock diff --git a/color-spantrace/src/lib.rs b/color-spantrace/src/lib.rs index 214799b..f3e8a48 100644 --- a/color-spantrace/src/lib.rs +++ b/color-spantrace/src/lib.rs @@ -59,12 +59,12 @@ //! //! [`tracing_error::SpanTrace`]: https://docs.rs/tracing-error/*/tracing_error/struct.SpanTrace.html //! [`color-backtrace`]: https://github.com/athre0z/color-backtrace -#![doc(html_root_url = "https://docs.rs/color-spantrace/0.2.1")] #![cfg_attr( nightly, feature(rustdoc_missing_doc_code_examples), warn(rustdoc::missing_doc_code_examples) )] +#![cfg_attr(docsrs, feature(doc_auto_cfg))] #![warn( missing_debug_implementations, missing_docs, @@ -85,6 +85,7 @@ unused_parens, while_true )] + use once_cell::sync::OnceCell; use owo_colors::{style, Style}; use std::env; diff --git a/eyre/Cargo.toml b/eyre/Cargo.toml index 6848126..ab26876 100644 --- a/eyre/Cargo.toml +++ b/eyre/Cargo.toml @@ -1,11 +1,11 @@ [package] name = "eyre" version = "1.0.0" -authors = ["David Tolnay ", "Jane Lusby "] description = "Flexible concrete Error Reporting type built on std::error::Error with customizable Reports" documentation = "https://docs.rs/eyre" categories = ["rust-patterns"] +authors = { workspace = true } edition = { workspace = true } license = { workspace = true } repository = { workspace = true } @@ -35,7 +35,8 @@ pyo3 = { version = "0.20", default-features = false, features = ["auto-initializ [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] -rustdoc-args = ["--cfg", "doc_cfg"] +all-features = true +rustdoc-args = ["--cfg", "docsrs"] [package.metadata.workspaces] independent = true diff --git a/eyre/src/lib.rs b/eyre/src/lib.rs index 33c60d3..8e9f003 100644 --- a/eyre/src/lib.rs +++ b/eyre/src/lib.rs @@ -328,12 +328,13 @@ //! [`simple-eyre`]: https://github.com/eyre-rs/simple-eyre //! [`color-spantrace`]: https://github.com/eyre-rs/color-spantrace //! [`color-backtrace`]: https://github.com/athre0z/color-backtrace -#![doc(html_root_url = "https://docs.rs/eyre/0.6.11")] #![cfg_attr( nightly, feature(rustdoc_missing_doc_code_examples), warn(rustdoc::missing_doc_code_examples) )] +#![cfg_attr(backtrace, feature(backtrace))] +#![cfg_attr(docsrs, feature(doc_auto_cfg))] #![warn( missing_debug_implementations, missing_docs, @@ -355,8 +356,6 @@ unused_parens, while_true )] -#![cfg_attr(backtrace, feature(backtrace))] -#![cfg_attr(doc_cfg, feature(doc_cfg))] #![allow( clippy::needless_doctest_main, clippy::new_ret_no_self, diff --git a/simple-eyre/CHANGELOG.md b/simple-eyre/CHANGELOG.md new file mode 100644 index 0000000..f9515ba --- /dev/null +++ b/simple-eyre/CHANGELOG.md @@ -0,0 +1,18 @@ +# Changelog +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + + + +## [Unreleased] - ReleaseDate + +## [0.3.1] - 2021-06-24 +# Fixed +- Fixed lifetime inference error caused by recent `std` change. + + + +[Unreleased]: https://github.com/eyre-rs/simple-eyre/compare/v0.3.1...HEAD +[0.3.1]: https://github.com/eyre-rs/simple-eyre/releases/tag/v0.3.1 diff --git a/simple-eyre/Cargo.toml b/simple-eyre/Cargo.toml new file mode 100644 index 0000000..1c71c81 --- /dev/null +++ b/simple-eyre/Cargo.toml @@ -0,0 +1,52 @@ +[package] +name = "simple-eyre" +version = "0.3.1" +documentation = "https://docs.rs/simple-eyre" +description = "One of the simplest error reporters one can build ontop of eyre, defining only an error report" + +authors = { workspace = true } +edition = { workspace = true } +license = { workspace = true } +repository = { workspace = true } +readme = { workspace = true } +rust-version = { workspace = true } + +[dependencies] +eyre = "0.6.0" +indenter = { workspace = true } + +[package.metadata.docs.rs] +all-features = true +rustdoc-args = ["--cfg", "docsrs"] + +[package.metadata.release] +no-dev-version = true + +[[package.metadata.release.pre-release-replacements]] +file = "CHANGELOG.md" +search = "Unreleased" +replace = "{{version}}" + +[[package.metadata.release.pre-release-replacements]] +file = "CHANGELOG.md" +search = "ReleaseDate" +replace = "{{date}}" + +[[package.metadata.release.pre-release-replacements]] +file = "CHANGELOG.md" +search = "" +replace = "\n\n## [Unreleased] - ReleaseDate" +exactly = 1 + +# Disable this replacement on the very first release +[[package.metadata.release.pre-release-replacements]] +file = "CHANGELOG.md" +search = "\\.\\.\\.HEAD" +replace = "...{{tag_name}}" +exactly = 1 + +[[package.metadata.release.pre-release-replacements]] +file = "CHANGELOG.md" +search = "" +replace = "\n[Unreleased]: https://github.com/eyre-rs/{{crate_name}}/compare/{{tag_name}}...HEAD" +exactly = 1 diff --git a/simple-eyre/LICENSE-APACHE b/simple-eyre/LICENSE-APACHE new file mode 120000 index 0000000..965b606 --- /dev/null +++ b/simple-eyre/LICENSE-APACHE @@ -0,0 +1 @@ +../LICENSE-APACHE \ No newline at end of file diff --git a/simple-eyre/LICENSE-MIT b/simple-eyre/LICENSE-MIT new file mode 120000 index 0000000..76219eb --- /dev/null +++ b/simple-eyre/LICENSE-MIT @@ -0,0 +1 @@ +../LICENSE-MIT \ No newline at end of file diff --git a/simple-eyre/README.md b/simple-eyre/README.md new file mode 100644 index 0000000..466f644 --- /dev/null +++ b/simple-eyre/README.md @@ -0,0 +1,51 @@ +## simple-eyre + +[![Latest Version](https://img.shields.io/crates/v/simple-eyre.svg)](https://crates.io/crates/simple-eyre) +[![Rust Documentation](https://img.shields.io/badge/api-rustdoc-blue.svg)](https://docs.rs/simple-eyre) + +This library provides a custom [`eyre::EyreHandler`] type for usage with [`eyre`] that provides +a minimal error report with no additional context. Essentially the minimal implementation of an +error reporter. + +## Setup + +Add the following to your toml file: + +```toml +[dependencies] +simple-eyre = "0.3" +``` + +Then install the hook handler before constructing any `eyre::Report` types. + +# Example + +```rust,should_panic +use simple_eyre::eyre::{eyre, WrapErr, Report}; + +fn main() -> Result<(), Report> { + simple_eyre::install()?; + + let e: Report = eyre!("oh no this program is just bad!"); + + Err(e).wrap_err("usage example successfully experienced a failure") +} +``` + +[`eyre::EyreHandler`]: https://docs.rs/eyre/*/eyre/trait.EyreHandler.html +[`eyre`]: https://docs.rs/eyre + +#### License + + +Licensed under either of Apache License, Version +2.0 or MIT license at your option. + + +
+ + +Unless you explicitly state otherwise, any contribution intentionally submitted +for inclusion in this crate by you, as defined in the Apache-2.0 license, shall +be dual licensed as above, without any additional terms or conditions. + diff --git a/simple-eyre/src/lib.rs b/simple-eyre/src/lib.rs new file mode 100644 index 0000000..c2a5ee5 --- /dev/null +++ b/simple-eyre/src/lib.rs @@ -0,0 +1,122 @@ +//! This library provides a custom [`eyre::EyreHandler`] type for usage with [`eyre`] that provides +//! a minimal error report with no additional context. Essentially the minimal implementation of an +//! error reporter. +//! +//! ## Setup +//! +//! Add the following to your toml file: +//! +//! ```toml +//! [dependencies] +//! simple-eyre = "0.3" +//! ``` +//! +//! Then install the hook handler before constructing any `eyre::Report` types. +//! +//! # Example +//! +//! ```rust,should_panic +//! use simple_eyre::eyre::{eyre, WrapErr, Report}; +//! +//! fn main() -> Result<(), Report> { +//! simple_eyre::install()?; +//! +//! let e: Report = eyre!("oh no this program is just bad!"); +//! +//! Err(e).wrap_err("usage example successfully experienced a failure") +//! } +//! ``` +//! +//! [`eyre::EyreHandler`]: https://docs.rs/eyre/*/eyre/trait.EyreHandler.html +//! [`eyre`]: https://docs.rs/eyre +#![cfg_attr( + nightly, + feature(rustdoc_missing_doc_code_examples), + warn(rustdoc::missing_doc_code_examples) +)] +#![cfg_attr(docsrs, feature(doc_auto_cfg))] +#![warn( + missing_debug_implementations, + missing_docs, + rust_2018_idioms, + unreachable_pub, + bad_style, + dead_code, + improper_ctypes, + non_shorthand_field_patterns, + no_mangle_generic_items, + overflowing_literals, + path_statements, + patterns_in_fns_without_body, + unconditional_recursion, + unused, + unused_allocation, + unused_comparisons, + unused_parens, + while_true +)] + +pub use eyre; +#[doc(hidden)] +pub use eyre::{Report, Result}; + +use eyre::EyreHandler; +use indenter::indented; +use std::error::Error; + +/// A custom context type for minimal error reporting via `eyre` +#[derive(Debug)] +pub struct Handler; + +impl EyreHandler for Handler { + fn debug( + &self, + error: &(dyn Error + 'static), + f: &mut core::fmt::Formatter<'_>, + ) -> core::fmt::Result { + use core::fmt::Write as _; + + if f.alternate() { + return core::fmt::Debug::fmt(error, f); + } + + write!(f, "{}", error)?; + + if let Some(cause) = error.source() { + write!(f, "\n\nCaused by:")?; + + let multiple = cause.source().is_some(); + let errors = std::iter::successors(Some(cause), |e| (*e).source()); + + for (n, error) in errors.enumerate() { + writeln!(f)?; + + if multiple { + write!(indented(f).ind(n), "{}", error)?; + } else { + write!(indented(f), "{}", error)?; + } + } + } + + Ok(()) + } +} + +/// Install the `simple-eyre` hook as the global error report hook. +/// +/// # Details +/// +/// This function must be called to enable the customization of `eyre::Report` +/// provided by `simple-eyre`. This function should be called early, ideally +/// before any errors could be encountered. +/// +/// Only the first install will succeed. Calling this function after another +/// report handler has been installed will cause an error. **Note**: This +/// function _must_ be called before any `eyre::Report`s are constructed to +/// prevent the default handler from being installed. +pub fn install() -> Result<()> { + crate::eyre::set_hook(Box::new(move |_| Box::new(Handler)))?; + + Ok(()) +}