| Crates.io | errcraft |
| lib.rs | errcraft |
| version | 0.1.0 |
| created_at | 2025-10-14 16:54:33.716408+00 |
| updated_at | 2025-10-14 16:54:33.716408+00 |
| description | Beautiful, structured, and colorful error handling for Rust. |
| homepage | |
| repository | https://gitlab.com/TIVisionOSS/crates/errcraft |
| max_upload_size | |
| id | 1882728 |
| size | 111,026 |
"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.
ErrFrame that wraps any error with rich contextanyhow, eyre, thiserror, tracing, and axumAdd to your Cargo.toml:
[dependencies]
errcraft = "0.1"
use errcraft::ErrFrame;
fn read_config(path: &str) -> Result<String, ErrFrame> {
std::fs::read_to_string(path).map_err(|e| {
ErrFrame::new("Failed to read configuration file")
.context("path", path)
.context("operation", "read")
.with_source(e)
})
}
fn main() {
if let Err(e) = read_config("config.toml") {
e.eprint(); // Beautiful error output!
}
}
Output:
โ Error: Failed to read configuration file
๐ฆ Context:
path = config.toml
operation = read
โ ๏ธ Caused by:
โโ No such file or directory (os error 2)
use errcraft::{craft, bail, ensure};
fn process_data(value: i32) -> Result<(), errcraft::ErrFrame> {
ensure!(value > 0, "Value must be positive, got {}", value);
if value > 100 {
bail!("Value too large: {}", value);
}
Ok(())
}
use errcraft::ErrFrame;
fn deep_function() -> Result<(), std::io::Error> {
Err(std::io::Error::new(
std::io::ErrorKind::NotFound,
"Configuration file not found",
))
}
fn middle_function() -> Result<(), ErrFrame> {
deep_function().map_err(|e| {
ErrFrame::new("Failed to load configuration")
.context("layer", "middleware")
.with_source(e)
})
}
fn top_function() -> Result<(), ErrFrame> {
middle_function().map_err(|e| {
ErrFrame::new("Application initialization failed")
.context("phase", "startup")
.with_source(e)
})
}
use errcraft::{DisplayOptions, ColorMode, BacktraceMode};
let opts = DisplayOptions::new()
.with_emoji(true)
.with_color(ColorMode::Always)
.with_max_depth(Some(5))
.with_backtrace(BacktraceMode::Shown);
let output = error.to_string_styled(&opts);
println!("{}", output);
NO_COLOR: Disable colorsRUST_BACKTRACE=1: Show backtracesstd (default): Standard library supportbacktrace (default): Capture and display backtracescolors-owo (default): Colorful output via owo-colorscolors-yansi: Alternative color backendcolors-anstyle: Alternative color backendemoji: Enable emoji glyphs in outputserde: JSON serialization supportmarkdown: Markdown renderinganyhow: Integration with anyhoweyre: Integration with eyrethiserror: Integration with thiserrortracing: Integration with tracingaxum: Integration with axum web frameworkNote: Only one colors-* feature can be enabled at a time.
Check out the examples directory:
simple.rs - Basic error creation and displaynested.rs - Nested error chainsasync_api.rs - Async context usagecli_output.rs - Output customizationRun an example:
cargo run --example simple
cargo run --example nested
cargo run --example cli_output --all-features
use errcraft::ErrFrame;
use axum::{routing::get, Router};
async fn handler() -> Result<String, ErrFrame> {
Err(ErrFrame::new("Something went wrong")
.context("endpoint", "/api/v1/data"))
}
let app = Router::new().route("/", get(handler));
use errcraft::ErrFrame;
let err = ErrFrame::new("Database error")
.context("table", "users");
err.trace_error(); // Logs to tracing
let err = ErrFrame::new("API error")
.context("code", 404);
let json = err.to_json_string();
println!("{}", json);
Run tests with:
cargo test --all-features
Run tests without default features:
cargo test --no-default-features --features std
Full API documentation is available at docs.rs/errcraft.
Contributions are welcome! Please read CONTRIBUTING.md for guidelines.
This project is licensed under the MIT License - see the LICENSE file for details.
Inspired by:
anyhow - Ergonomic error handlingeyre - Flexible error reportingthiserror - Derive macros for error typescolor-eyre - Colorful error reportsAuthor: Eshan Roy
Organization: Tonmoy Infrastructure
Repository: https://gitlab.com/TIVisionOSS/crates/errcraft
"A well-crafted error message is the best form of documentation."