Skip to content
Draft
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
4 changes: 2 additions & 2 deletions color-eyre/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ color-eyre = "0.6"
And install the panic and error report handlers:

```rust
use color_eyre::eyre::Result;
use color_eyre::Result;

fn main() -> Result<()> {
color_eyre::install()?;
Expand Down Expand Up @@ -129,7 +129,7 @@ to contain `stderr` and `stdout` from a failed command, taken from
[`examples/custom_section.rs`]:

```rust
use color_eyre::{eyre::eyre, SectionExt, Section, eyre::Report};
use color_eyre::{eyre, SectionExt, Section, Report};
use std::process::Command;
use tracing::instrument;

Expand Down
2 changes: 1 addition & 1 deletion color-eyre/examples/custom_filter.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use color_eyre::{Section, eyre::Report, eyre::ResultExt};
use color_eyre::{Report, ResultExt, Section};
use tracing::{info, instrument};

#[instrument]
Expand Down
4 changes: 1 addition & 3 deletions color-eyre/examples/custom_section.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use color_eyre::{
Section, SectionExt,
eyre::Report,
eyre::{ResultExt, eyre},
Report, Section, SectionExt, {ResultExt, eyre},
};
use std::process::Command;
use tracing::instrument;
Expand Down
6 changes: 1 addition & 5 deletions color-eyre/examples/debug_perf.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
//! example for manually testing the perf of color-eyre in debug vs release

use color_eyre::{
Section,
eyre::Report,
eyre::{ResultExt, eyre},
};
use color_eyre::{Report, ResultExt, Section, eyre};
use tracing::instrument;

fn main() -> Result<(), Report> {
Expand Down
5 changes: 3 additions & 2 deletions color-eyre/examples/github_issue.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![allow(dead_code, unused_imports)]
use color_eyre::eyre;
use eyre::{Report, Result};
use color_eyre::{
eyre, {Report, Result},
};
use tracing::instrument;

#[instrument]
Expand Down
2 changes: 1 addition & 1 deletion color-eyre/examples/multiple_errors.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use color_eyre::{Section, eyre::Report, eyre::eyre};
use color_eyre::{Report, Section, eyre};
use thiserror::Error;

fn main() -> Result<(), Report> {
Expand Down
2 changes: 1 addition & 1 deletion color-eyre/examples/panic_compose.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use color_eyre::eyre::Report;
use color_eyre::Report;
use tracing::instrument;

#[instrument]
Expand Down
2 changes: 1 addition & 1 deletion color-eyre/examples/panic_hook.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use color_eyre::eyre::Report;
use color_eyre::Report;
use tracing::instrument;

#[instrument]
Expand Down
2 changes: 1 addition & 1 deletion color-eyre/examples/theme.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use color_eyre::{Section, config::Theme, eyre::Report, owo_colors::style};
use color_eyre::{Report, Section, config::Theme, owo_colors::style};

/// To experiment with theme values, edit `theme()` below and execute `cargo run --example theme`
fn theme() -> Theme {
Expand Down
2 changes: 1 addition & 1 deletion color-eyre/examples/theme_test_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

//! See "tests/theme.rs" for more information.

use color_eyre::{Section, eyre::Report};
use color_eyre::{Report, Section};

#[rustfmt::skip]
#[derive(Debug, thiserror::Error)]
Expand Down
2 changes: 1 addition & 1 deletion color-eyre/examples/usage.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use color_eyre::{Section, eyre::Report, eyre::ResultExt};
use color_eyre::{Report, ResultExt, Section};
use tracing::{info, instrument};

#[instrument]
Expand Down
31 changes: 17 additions & 14 deletions color-eyre/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,9 +420,7 @@ impl HookBuilder {
/// ```rust
/// use color_eyre::config::HookBuilder;
///
/// HookBuilder::new()
/// .install()
/// .unwrap();
/// HookBuilder::new().install().unwrap();
/// ```
pub fn new() -> Self {
Self::blank()
Expand Down Expand Up @@ -480,9 +478,9 @@ impl HookBuilder {
/// # Examples
///
/// ```rust
/// use std::{panic::Location, fmt};
/// use color_eyre::section::PanicMessage;
/// use owo_colors::OwoColorize;
/// use std::{fmt, panic::Location};
///
/// struct MyPanicMessage;
///
Expand All @@ -492,7 +490,11 @@ impl HookBuilder {
/// .unwrap();
///
/// impl PanicMessage for MyPanicMessage {
/// fn display(&self, pi: &std::panic::PanicInfo<'_>, f: &mut fmt::Formatter<'_>) -> fmt::Result {
/// fn display(
/// &self,
/// pi: &std::panic::PanicInfo<'_>,
/// f: &mut fmt::Formatter<'_>,
/// ) -> fmt::Result {
/// writeln!(f, "{}", "The application panicked (crashed).".red())?;
///
/// // Print panic message.
Expand All @@ -513,7 +515,11 @@ impl HookBuilder {
/// write!(f, ":")?;
/// write!(f, "{}", loc.line().purple())?;
///
/// write!(f, "\n\nConsider reporting the bug at {}", custom_url(loc, payload))?;
/// write!(
/// f,
/// "\n\nConsider reporting the bug at {}",
/// custom_url(loc, payload)
/// )?;
/// } else {
/// write!(f, "<unknown>")?;
/// }
Expand Down Expand Up @@ -603,7 +609,6 @@ impl HookBuilder {
/// })
/// .install()
/// .unwrap();
///
#[cfg(feature = "issue-url")]
pub fn issue_filter<F>(mut self, predicate: F) -> Self
where
Expand Down Expand Up @@ -643,9 +648,7 @@ impl HookBuilder {
/// ```rust
/// color_eyre::config::HookBuilder::default()
/// .add_frame_filter(Box::new(|frames| {
/// let filters = &[
/// "uninteresting_function",
/// ];
/// let filters = &["uninteresting_function"];
///
/// frames.retain(|frame| {
/// !filters.iter().any(|f| {
Expand All @@ -668,7 +671,7 @@ impl HookBuilder {
}

/// Install the given Hook as the global error report hook
pub fn install(self) -> Result<(), crate::eyre::Report> {
pub fn install(self) -> Result<(), crate::Report> {
let (panic_hook, eyre_hook) = self.try_into_hooks()?;
eyre_hook.install()?;
panic_hook.install();
Expand All @@ -689,7 +692,7 @@ impl HookBuilder {

/// Create a `PanicHook` and `EyreHook` from this `HookBuilder`.
/// This can be used if you want to combine these handlers with other handlers.
pub fn try_into_hooks(self) -> Result<(PanicHook, EyreHook), crate::eyre::Report> {
pub fn try_into_hooks(self) -> Result<(PanicHook, EyreHook), crate::Report> {
let theme = self.theme;
#[cfg(feature = "issue-url")]
let metadata = Arc::new(self.issue_metadata);
Expand Down Expand Up @@ -1065,8 +1068,8 @@ impl EyreHook {
}

/// Installs self as the global eyre handling hook via `eyre::set_hook`
pub fn install(self) -> Result<(), crate::eyre::InstallError> {
crate::eyre::set_hook(self.into_eyre_hook())
pub fn install(self) -> Result<(), crate::InstallError> {
crate::set_hook(self.into_eyre_hook())
}

/// Convert the self into the boxed type expected by `eyre::set_hook`.
Expand Down
16 changes: 6 additions & 10 deletions color-eyre/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
//! And install the panic and error report handlers:
//!
//! ```rust
//! use color_eyre::eyre::Result;
//! use color_eyre::Result;
//!
//! fn main() -> Result<()> {
//! color_eyre::install()?;
Expand Down Expand Up @@ -230,7 +230,7 @@
//! [`examples/custom_section.rs`]:
//!
//! ```rust
//! use color_eyre::{eyre::eyre, SectionExt, Section, eyre::Report};
//! use color_eyre::{eyre, Report, Section, SectionExt};
//! use std::process::Command;
//! use tracing::instrument;
//!
Expand Down Expand Up @@ -362,11 +362,7 @@ use std::sync::Arc;
#[doc(hidden)]
pub use Handler as Context;
use backtrace::Backtrace;
pub use eyre;
#[doc(hidden)]
pub use eyre::Report;
#[doc(hidden)]
pub use eyre::Result;
pub use eyre::*;
pub use owo_colors;
#[doc(hidden)]
pub use section::Section as Help;
Expand All @@ -378,7 +374,7 @@ use tracing_error::SpanTrace;
pub mod config;
mod fmt;
mod handler;
pub(crate) mod private;
pub(crate) mod sealed;
pub mod section;
mod writers;

Expand Down Expand Up @@ -446,7 +442,7 @@ pub enum ErrorKind<'a> {
/// # Examples
///
/// ```rust
/// use color_eyre::eyre::Result;
/// use color_eyre::Result;
///
/// fn main() -> Result<()> {
/// color_eyre::install()?;
Expand All @@ -455,6 +451,6 @@ pub enum ErrorKind<'a> {
/// # Ok(())
/// }
/// ```
pub fn install() -> Result<(), crate::eyre::Report> {
pub fn install() -> Result<(), crate::Report> {
config::HookBuilder::default().install()
}
2 changes: 1 addition & 1 deletion color-eyre/src/private.rs → color-eyre/src/sealed.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::eyre::Report;
use crate::Report;
pub trait Sealed {}

impl<T, E> Sealed for std::result::Result<T, E> where E: Into<Report> {}
Expand Down
6 changes: 1 addition & 5 deletions color-eyre/src/section/help.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
//! Provides an extension trait for attaching `Section` to error reports.
use crate::{
Section,
config::Theme,
eyre::{Report, Result},
};
use crate::{Report, Result, Section, config::Theme};
use indenter::indented;
use owo_colors::OwoColorize;
use std::fmt::Write;
Expand Down
31 changes: 16 additions & 15 deletions color-eyre/src/section/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub(crate) mod help;
/// # Examples
///
/// ```rust
/// use color_eyre::{eyre::eyre, SectionExt, Section, eyre::Report};
/// use color_eyre::{eyre, Report, Section, SectionExt};
/// use std::process::Command;
/// use tracing::instrument;
///
Expand Down Expand Up @@ -88,7 +88,7 @@ pub trait SectionExt: Sized {
/// # Examples
///
/// ```rust,no_run
/// use color_eyre::{eyre::eyre, Section, SectionExt, eyre::Report};
/// use color_eyre::{eyre, Report, Section, SectionExt};
///
/// let all_in_header = "header\n body\n body";
/// let report = Err::<(), Report>(eyre!("an error occurred"))
Expand Down Expand Up @@ -133,7 +133,7 @@ where
/// sections are displayed after all other sections with no extra newlines between subsequent Help
/// sections. They consist only of a header portion and are prepended with a colored string
/// indicating the kind of section, e.g. `Note: This might have failed due to ..."
pub trait Section: crate::private::Sealed {
pub trait Section: crate::sealed::Sealed {
/// The return type of each method after adding context
type Return;

Expand All @@ -149,10 +149,9 @@ pub trait Section: crate::private::Sealed {
/// # Examples
///
/// ```rust,should_panic
/// use color_eyre::{eyre::eyre, eyre::Report, Section};
/// use color_eyre::{eyre, Report, Section};
///
/// Err(eyre!("command failed"))
/// .section("Please report bugs to https://real.url/bugs")?;
/// Err(eyre!("command failed")).section("Please report bugs to https://real.url/bugs")?;
/// # Ok::<_, Report>(())
/// ```
fn section<D>(self, section: D) -> Self::Return
Expand All @@ -165,12 +164,11 @@ pub trait Section: crate::private::Sealed {
/// # Examples
///
/// ```rust
/// use color_eyre::{eyre::eyre, eyre::Report, Section, SectionExt};
/// use color_eyre::{eyre, Report, Section, SectionExt};
///
/// # #[cfg(not(miri))]
/// # {
/// let output = std::process::Command::new("ls")
/// .output()?;
/// let output = std::process::Command::new("ls").output()?;
///
/// let output = if !output.status.success() {
/// let stderr = String::from_utf8_lossy(&output.stderr);
Expand All @@ -195,7 +193,7 @@ pub trait Section: crate::private::Sealed {
/// # Examples
///
/// ```rust,should_panic
/// use color_eyre::{eyre::eyre, eyre::Report, Section};
/// use color_eyre::{eyre, Report, Section};
/// use thiserror::Error;
///
/// #[derive(Debug, Error)]
Expand All @@ -217,7 +215,7 @@ pub trait Section: crate::private::Sealed {
/// # Examples
///
/// ```rust,should_panic
/// use color_eyre::{eyre::eyre, eyre::Report, Section};
/// use color_eyre::{eyre, Report, Section};
/// use thiserror::Error;
///
/// #[derive(Debug, Error)]
Expand All @@ -240,7 +238,7 @@ pub trait Section: crate::private::Sealed {
///
/// ```rust
/// # use std::{error::Error, fmt::{self, Display}};
/// # use color_eyre::eyre::Result;
/// # use color_eyre::Result;
/// # #[derive(Debug)]
/// # struct FakeErr;
/// # impl Display for FakeErr {
Expand Down Expand Up @@ -270,7 +268,7 @@ pub trait Section: crate::private::Sealed {
///
/// ```rust
/// # use std::{error::Error, fmt::{self, Display}};
/// # use color_eyre::eyre::Result;
/// # use color_eyre::Result;
/// # #[derive(Debug)]
/// # struct FakeErr;
/// # impl Display for FakeErr {
Expand All @@ -286,8 +284,11 @@ pub trait Section: crate::private::Sealed {
/// use color_eyre::Section as _;
///
/// fallible_fn().with_note(|| {
/// format!("This might have failed due to ... It has failed {} times", 100)
/// })?;
/// format!(
/// "This might have failed due to ... It has failed {} times",
/// 100
/// )
/// })?;
Comment on lines +287 to +291

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some unrelated changes like this in doc comments as I formatted the code with rustfmt's format_doc_in_comments option to fix ordering of use statements. If you don't mind I would like to keep them, but it's no issue to remove them or split them in a different PR.

/// # Ok(())
/// # }
/// ```
Expand Down
1 change: 0 additions & 1 deletion color-eyre/tests/bt_disabled.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use color_eyre::eyre;
use eyre::eyre;

#[test]
fn disabled() {
Expand Down
1 change: 0 additions & 1 deletion color-eyre/tests/bt_enabled.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use color_eyre::eyre;
use eyre::eyre;

#[test]
fn enabled() {
Expand Down
1 change: 0 additions & 1 deletion color-eyre/tests/location_disabled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#[test]
fn disabled() {
use color_eyre::eyre;
use eyre::eyre;

color_eyre::config::HookBuilder::default()
.display_location_section(false)
Expand Down
2 changes: 1 addition & 1 deletion color-eyre/tests/theme.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Note: It's recommended, not to change anything above or below (see big comment below)

use color_eyre::{Section, eyre::Report};
use color_eyre::{Report, Section};

#[rustfmt::skip]
#[derive(Debug, thiserror::Error)]
#[error("{0}")]
struct TestError(&'static str);

Check warning on line 8 in color-eyre/tests/theme.rs

View workflow job for this annotation

GitHub Actions / Miri

struct `TestError` is never constructed

#[rustfmt::skip]
#[tracing::instrument]
Expand Down Expand Up @@ -36,7 +36,7 @@
static ERROR_FILE_NAME: &str = "theme_error_control_spantrace.txt";

#[cfg(all(feature = "capture-spantrace", feature = "track-caller",))]
static ERROR_FILE_NAME: &str = "theme_error_control.txt";

Check warning on line 39 in color-eyre/tests/theme.rs

View workflow job for this annotation

GitHub Actions / Miri

static `ERROR_FILE_NAME` is never used

#[rustversion::attr(nightly, ignore)]
#[test]
Expand Down Expand Up @@ -98,7 +98,7 @@
static PANIC_FILE_NAME: &str = "theme_panic_control_no_spantrace.txt";

#[cfg(feature = "capture-spantrace")]
static PANIC_FILE_NAME: &str = "theme_panic_control.txt";

Check warning on line 101 in color-eyre/tests/theme.rs

View workflow job for this annotation

GitHub Actions / Miri

static `PANIC_FILE_NAME` is never used

// The following tests the installed panic handler
#[rustversion::attr(nightly, ignore)]
Expand Down Expand Up @@ -136,7 +136,7 @@
}

/// Helper for `test_error` and `test_panic`
fn test_backwards_compatibility(target: String, file_name: &str) {

Check warning on line 139 in color-eyre/tests/theme.rs

View workflow job for this annotation

GitHub Actions / Miri

function `test_backwards_compatibility` is never used
use ansi_parser::{AnsiParser, AnsiSequence, Output};
use owo_colors::OwoColorize;
use std::{fs, path::Path};
Expand Down Expand Up @@ -254,7 +254,7 @@
*/
}

fn setup() {

Check warning on line 257 in color-eyre/tests/theme.rs

View workflow job for this annotation

GitHub Actions / Miri

function `setup` is never used
unsafe { std::env::set_var("RUST_LIB_BACKTRACE", "1") };

#[cfg(feature = "capture-spantrace")]
Expand Down
Loading
Loading