๐ฅ errcraft
"Beautiful Errors. Crafted for Humans and Rustaceans alike."
errcraft is a Rust library that transforms error handling into an elegant, human-centric experience. It provides composable error types with rich context, nested chaining, beautiful CLI rendering, and seamless integration with the Rust ecosystem.
โจ Features
- ๐งฉ Universal Error Type: A composable
ErrFramethat wraps any error with rich context - ๐ฒ Nested Error Trees: Trace errors across layers with perfect indentation
- ๐จ Beautiful CLI Rendering: Colorful, emoji-enhanced output with auto TTY detection
- ๐ง Smart Context: Attach key-value pairs and text annotations
- ๐ Smart Backtraces: Captured conditionally and filtered for clarity
- โ๏ธ Ecosystem Integration: Works with
anyhow,eyre,thiserror,tracing, andaxum - ๐ฆ Serialization: JSON and Markdown output for logs and APIs
- ๐ง Zero Config: Beautiful errors out of the box, customize when needed
๐ Quick Start
Add to your Cargo.toml:
[]
= "0.1"
Basic Usage
use ErrFrame;
Output:
โ Error: Failed to read configuration file
๐ฆ Context:
path = config.toml
operation = read
โ ๏ธ Caused by:
โโ No such file or directory (os error 2)
Using Macros
use ;
Nested Errors
use ErrFrame;
๐จ Customization
Display Options
use ;
let opts = new
.with_emoji
.with_color
.with_max_depth
.with_backtrace;
let output = error.to_string_styled;
println!;
Environment Variables
NO_COLOR: Disable colorsRUST_BACKTRACE=1: Show backtraces
๐งฉ Feature Flags
std(default): Standard library supportbacktrace(default): Capture and display backtracescolors-owo(default): Colorful output viaowo-colorscolors-yansi: Alternative color backendcolors-anstyle: Alternative color backendemoji: Enable emoji glyphs in outputserde: JSON serialization supportmarkdown: Markdown renderinganyhow: Integration withanyhoweyre: Integration witheyrethiserror: Integration withthiserrortracing: Integration withtracingaxum: Integration withaxumweb framework
Note: Only one colors-* feature can be enabled at a time.
๐ Examples
Check out the examples directory:
simple.rs- Basic error creation and displaynested.rs- Nested error chainsasync_api.rs- Async context usagecli_output.rs- Output customization
Run an example:
๐ง Integration Examples
With Axum
use ErrFrame;
use ;
async
let app = new.route;
With Tracing
use ErrFrame;
let err = new
.context;
err.trace_error; // Logs to tracing
With Serde
let err = new
.context;
let json = err.to_json_string;
println!;
๐งช Testing
Run tests with:
Run tests without default features:
๐ Documentation
Full API documentation is available at docs.rs/errcraft.
๐ค Contributing
Contributions are welcome! Please read CONTRIBUTING.md for guidelines.
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
Inspired by:
anyhow- Ergonomic error handlingeyre- Flexible error reportingthiserror- Derive macros for error typescolor-eyre- Colorful error reports
๐ฌ Contact
Author: Eshan Roy
Organization: Tonmoy Infrastructure
Repository: https://gitlab.com/TIVisionOSS/crates/errcraft
"A well-crafted error message is the best form of documentation."