Crate ees

source · []
Expand description

This library is intended to provide simple error-handling-related helper functions and types. Rather than provide its own error-related types, it is centered around the std::error::Error trait.

Usage:

use std::io::Read;

// Use ees::Error for arbitrary owned errors
// You can also use ees::Result<()> as a shorthand
fn do_work() -> Result<(), ees::Error> {
    let mut file = std::fs::File::open("hello world")?;
    let mut contents = String::new();
    file.read_to_string(&mut contents)?;
    if contents.is_empty() {
        // Construct an error on the fly
        ees::bail!("file is empty");
    }
    Ok(())
}

// Take an arbitrary borrowed error
fn take_an_error(error: ees::ErrorRef<'_>) {
    // Print the complete error chain
    println!("Error: {}", ees::print_error_chain(error));
}

// Use ees::MainResult to automatically create nicely-
// formatted error messages in the main() function
fn main() -> ees::MainResult {
    do_work()?;
    do_work().map_err(
        // add additional context
        |e| ees::wrap!(e, "failed to do work"))?;
    Ok(())
}

Macros

Construct an error on the fly, and immediately return from the current function

Construct an error on the fly

Wrap an error in a new on-the-fly error

Structs

This type wraps an arbitrary error, and is intended for use in the main() method

Functions

Print the complete error chain of an error, separated with colons

Convert any error into a type that implements std::error::Error. This is mainly useful for converting Error types to anyhow::Error or similar.

Type Definitions

Represents an arbitrary owned error

Represents an arbitrary borrowed error with a given lifetime

A convenient way to return arbitrary errors from main()

Result<T, Error>