mirror of
https://github.com/eyre-rs/eyre.git
synced 2025-09-27 13:01:29 +00:00
Add 'simple-eyre/' from commit 'bcfff0f56f278dca96cdd45de0e741227f15f3b0'
git-subtree-dir: simple-eyre git-subtree-mainline: 7a5c32acd7a4a6139448b7900a6787f70b5b69fb git-subtree-split: bcfff0f56f278dca96cdd45de0e741227f15f3b0
This commit is contained in:
commit
a6a2e0eb2b
121
simple-eyre/.github/workflows/ci.yml
vendored
Normal file
121
simple-eyre/.github/workflows/ci.yml
vendored
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
pull_request: {}
|
||||||
|
|
||||||
|
name: Continuous integration
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
check:
|
||||||
|
name: Check
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
rust:
|
||||||
|
- stable
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: actions-rs/toolchain@v1
|
||||||
|
with:
|
||||||
|
toolchain: ${{ matrix.rust }}
|
||||||
|
override: true
|
||||||
|
- uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
command: check
|
||||||
|
|
||||||
|
test-features:
|
||||||
|
name: Test Suite
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- 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@v2
|
||||||
|
- uses: actions-rs/toolchain@v1
|
||||||
|
with:
|
||||||
|
toolchain: ${{ matrix.rust }}
|
||||||
|
override: true
|
||||||
|
- uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
command: test
|
||||||
|
|
||||||
|
test-os:
|
||||||
|
name: Test Suite
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-latest, windows-latest, macOS-latest]
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: actions-rs/toolchain@v1
|
||||||
|
with:
|
||||||
|
toolchain: stable
|
||||||
|
override: true
|
||||||
|
profile: minimal
|
||||||
|
- uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
command: test
|
||||||
|
|
||||||
|
fmt:
|
||||||
|
name: Rustfmt
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
rust:
|
||||||
|
- stable
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- 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: --all-targets --all-features -- -D warnings
|
2
simple-eyre/.gitignore
vendored
Normal file
2
simple-eyre/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
/target
|
||||||
|
Cargo.lock
|
18
simple-eyre/CHANGELOG.md
Normal file
18
simple-eyre/CHANGELOG.md
Normal file
@ -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).
|
||||||
|
|
||||||
|
<!-- next-header -->
|
||||||
|
|
||||||
|
## [Unreleased] - ReleaseDate
|
||||||
|
|
||||||
|
## [0.3.1] - 2021-06-24
|
||||||
|
# Fixed
|
||||||
|
- Fixed lifetime inference error caused by recent `std` change.
|
||||||
|
|
||||||
|
|
||||||
|
<!-- next-url -->
|
||||||
|
[Unreleased]: https://github.com/yaahc/simple-eyre/compare/v0.3.1...HEAD
|
||||||
|
[0.3.1]: https://github.com/yaahc/displaydoc/releases/tag/v0.3.1
|
61
simple-eyre/Cargo.toml
Normal file
61
simple-eyre/Cargo.toml
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
[package]
|
||||||
|
name = "simple-eyre"
|
||||||
|
version = "0.3.1"
|
||||||
|
authors = ["Jane Lusby <jlusby@yaah.dev>"]
|
||||||
|
edition = "2018"
|
||||||
|
license = "MIT OR Apache-2.0"
|
||||||
|
readme = "README.md"
|
||||||
|
repository = "https://github.com/yaahc/simple-eyre"
|
||||||
|
homepage = "https://github.com/yaahc/simple-eyre"
|
||||||
|
documentation = "https://docs.rs/simple-eyre"
|
||||||
|
keywords = ["error"]
|
||||||
|
description = """
|
||||||
|
One of the simplest error reporters one can build ontop of eyre, defining only an error report
|
||||||
|
"""
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
eyre = "0.6.0"
|
||||||
|
indenter = "0.3.0"
|
||||||
|
|
||||||
|
[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 = "src/lib.rs"
|
||||||
|
search = "#!\\[doc\\(html_root_url.*"
|
||||||
|
replace = "#![doc(html_root_url = \"https://docs.rs/{{crate_name}}/{{version}}\")]"
|
||||||
|
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="<!-- next-header -->"
|
||||||
|
replace="<!-- next-header -->\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
|
||||||
|
# END SECTION, do not comment out the replacement below this, and do not reorder them
|
||||||
|
|
||||||
|
[[package.metadata.release.pre-release-replacements]]
|
||||||
|
file="CHANGELOG.md"
|
||||||
|
search="<!-- next-url -->"
|
||||||
|
replace="<!-- next-url -->\n[Unreleased]: https://github.com/yaahc/{{crate_name}}/compare/{{tag_name}}...HEAD"
|
||||||
|
exactly=1
|
51
simple-eyre/README.md
Normal file
51
simple-eyre/README.md
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
## simple-eyre
|
||||||
|
|
||||||
|
[](https://crates.io/crates/simple-eyre)
|
||||||
|
[](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
|
||||||
|
|
||||||
|
<sup>
|
||||||
|
Licensed under either of <a href="LICENSE-APACHE">Apache License, Version
|
||||||
|
2.0</a> or <a href="LICENSE-MIT">MIT license</a> at your option.
|
||||||
|
</sup>
|
||||||
|
|
||||||
|
<br>
|
||||||
|
|
||||||
|
<sub>
|
||||||
|
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.
|
||||||
|
</sub>
|
119
simple-eyre/src/lib.rs
Normal file
119
simple-eyre/src/lib.rs
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
//! 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
|
||||||
|
#![doc(html_root_url = "https://docs.rs/simple-eyre/0.3.1")]
|
||||||
|
#![warn(
|
||||||
|
missing_debug_implementations,
|
||||||
|
missing_docs,
|
||||||
|
missing_doc_code_examples,
|
||||||
|
rust_2018_idioms,
|
||||||
|
unreachable_pub,
|
||||||
|
bad_style,
|
||||||
|
const_err,
|
||||||
|
dead_code,
|
||||||
|
improper_ctypes,
|
||||||
|
non_shorthand_field_patterns,
|
||||||
|
no_mangle_generic_items,
|
||||||
|
overflowing_literals,
|
||||||
|
path_statements,
|
||||||
|
patterns_in_fns_without_body,
|
||||||
|
private_in_public,
|
||||||
|
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(())
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user