okerr - Ergonomic result / error handling
okerr is a ergonomic result / error handling helpers built on anyhow and thiserror.
Most Rust projects handle errors with anyhow or eyre, and thiserror (for derive(Error)). Sometimes we have to juggle between.
okerr solves the problem, this crate makes this more convenient by providing consistency and an idiomatic API.
The okerr crate is mostly re-exported from anyhow, making it 100% compatible in both directions.
Thanks to okerr::from_boxed_error, it's easy to capture and convert eyre errors without including eyre as a dependency!
All of that in just a few lines of code (very lightweight, no overhead, no abstraction cost). Fully tested, of course!
Idiomatic aliases for clearer code:
anyerr!; // Instead of `anyhow!("Oops!")
err!; // Instead of `Err(anyhow!("Oops!")) or `Err(anyerr!("Oops!"))
fail!; // Instead of `bail!("Oops!")
// ---
use Error;
// Instead of
use Error;
// ---
// Convert from a boxed error (like eyre::Report)
let error = from_boxed_error
// Create/convert from any std::error::Error
let error = anyerr!
// Create/convert from a string
let error = anyerr!
// Wrap a Result into an okerr::Error
// Equivalent to result.map_err(okerr::Error::new)
let result = wrap_err
It's very simple, very lightweight (just a few lines of code in the okerr crate), it provides consistency and a excellent DX. 100% compatible with anyhow and thiserror, convert easily error from a boxed error (like eyre::Report and others).
Related docs
Examples
Anyhow like
With okerr::Result, okerr::err!, okerr::fail! and okerr::anyerr!:
use ;
Thiserror like
NOTE: requieres the
thiserrordependency to be added to yourCargo.toml(cargo add thiserror).
With okerr::derive::Error:
use ;
Tests
okerr is fully tested! Run all tests:
Thanks
Thanks to @dtolnay, the author of anyhow and thiserror, for providing two great ways to handle errors in Rust. 👍
LICENSE
MIT (c) 2025, Nicolas Talle.
Author
Buy me a coffee ☕ via PayPal!