eyre-rs / color-eyre

Custom hooks for colorful human oriented error reports via panics and the eyre crate
Other
958 stars 57 forks source link

Attach Report's to an error via Section::error() #122

Open SergeyKasmy opened 1 year ago

SergeyKasmy commented 1 year ago

Currently it is not possible to attach reports to an error via the section trait as the Section::error() method takes a type that must implement Error which Report does not. Since it's not possible to implement Error for Report, are there any plans of adding Section::report_error() or something similar to support that use-case?

For example, this doesn't work:

let results: Vec<Result<(), Report>> = job();
let errors = results.into_iter().filter_map(|res| match res {
        Ok(()) => None,
        Err(e) => Some(e),
    }).collect::<Vec<Report>>();

if errors.is_empty() {
    return Ok(());
}

let error = errors.into_iter().fold(
    eyre!("{} jobs have finished with an error", errors.len()),
    |acc, err| acc.error(err),
);

Err(error)