A structured error handling framework for Rust that tells you what went wrong, where, and how to fix it.
Yoshi provides rich, structured errors with context and metadata instead of generic "something broke" messages. It combines the ergonomics of anyhow with the type safety of thiserror, while adding powerful features like error categorization, suggestions, and metadata.
[dependencies]
yoshi = "0.1"use yoshi::*;
fn load_config(path: &str) -> Result<String> {
std::fs::read_to_string(path).map_err(|e| yoshi!(
YoshiKind::Io,
"Failed to read config file",
path: path,
source: e,
suggestion: "Check file permissions and path"
))
}
fn main() -> Result<()> {
match load_config("/etc/app/config.toml") {
Ok(config) => println!("Config: {}", config),
Err(err) => {
// Rich, formatted error output
eprintln!("Error: {}", err);
// With full context chain
eprintln!("Context: {:#}", err);
return Err(err);
}
}
Ok(())
}- Powerful Macros - Create rich errors with one line using
yoshi!,bail!, andensure! - Structured Categories - Categorize errors with
YoshiKindfor consistent handling - Rich Context - Capture and chain context as errors bubble up
- Metadata & Suggestions - Attach debugging data and provide fix suggestions
- Derive Support - Generate error types and conversions with
#[derive(YoshiError)] - No-std Compatible - Works in embedded environments
// Use the expressive yoshi! macro
let error = yoshi!(
YoshiKind::Database,
"Failed to connect to database",
host: "db.example.com",
port: 5432,
retry_count: 3,
suggestion: "Check database credentials and firewall settings"
);
// Or derive your own error types
use yoshi_derive::YoshiError;
#[derive(Debug, YoshiError)]
pub enum ApiError {
#[yoshi(kind = "NotFound")]
#[yoshi(display = "User {user_id} not found")]
UserNotFound { user_id: u64 },
#[yoshi(kind = "Timeout")]
RequestTimeout { seconds: u64 },
}- Introduction & Concepts
- Macro Guide
- Error Context & Metadata
- Performance Details
- Migration Guide
- API Docs
- Examples
Licensed under either of Apache License, Version 2.0 or MIT License at your option.
Made by ArcMoon Studios
