| Crates.io | yoshi-derive |
| lib.rs | yoshi-derive |
| version | 0.1.5 |
| created_at | 2025-06-01 19:17:21.772095+00 |
| updated_at | 2025-06-04 07:25:16.848661+00 |
| description | Procedural-macro helpers for deriving Yoshi errors. |
| homepage | |
| repository | https://github.com/arcmoonstudios/yoshi |
| max_upload_size | |
| id | 1697433 |
| size | 140,242 |

Derive macros for automatically generating Yoshi error types. Because writing error boilerplate is boring.
Generates std::error::Error implementations, Display, and conversion to Yoshi types automatically.
[dependencies]
yoshi-derive = "0.1"
yoshi = "0.1"
use yoshi_derive::YoshiError;
#[derive(Debug, YoshiError)]
pub enum MyError {
#[yoshi(display = "User {user_id} not found")]
#[yoshi(kind = "NotFound")]
UserNotFound { user_id: u32 },
#[yoshi(display = "Failed to parse config: {source}")]
ParseError {
#[yoshi(source)]
source: std::io::Error,
#[yoshi(context = "config_file")]
path: String,
},
}
#[yoshi(...)] on enums)| Attribute | Description | Example |
|---|---|---|
error_code_prefix |
Prefix for error codes | #[yoshi(error_code_prefix = "HTTP")] |
default_severity |
Default severity (0-255) | #[yoshi(default_severity = 75)] |
#[yoshi(...)] on enum variants)| Attribute | Description | Example |
|---|---|---|
display |
Custom display format | #[yoshi(display = "Error: {message}")] |
kind |
Map to YoshiKind | #[yoshi(kind = "Network")] |
error_code |
Unique error code | #[yoshi(error_code = 1001)] |
severity |
Severity level | #[yoshi(severity = 80)] |
transient |
Mark as retryable | #[yoshi(transient = true)] |
suggestion |
Recovery suggestion | #[yoshi(suggestion = "Check network")] |
#[yoshi(...)] on struct fields)| Attribute | Description | Example |
|---|---|---|
source |
Mark as error source | #[yoshi(source)] |
context |
Add to context metadata | #[yoshi(context = "file_path")] |
shell |
Add as typed shell | #[yoshi(shell)] |
skip |
Skip in Display | #[yoshi(skip)] |
use yoshi_derive::YoshiError;
#[derive(Debug, YoshiError)]
#[yoshi(error_code_prefix = "DB")]
#[yoshi(default_severity = 75)]
pub enum DatabaseError {
#[yoshi(error_code = 1001)]
#[yoshi(display = "Connection to {host}:{port} failed")]
#[yoshi(kind = "Network")]
#[yoshi(severity = 120)]
#[yoshi(transient = true)]
ConnectionFailed {
host: String,
port: u16,
#[yoshi(source)]
cause: std::io::Error,
#[yoshi(context = "connection_timeout")]
timeout: std::time::Duration,
},
#[yoshi(error_code = 2001)]
#[yoshi(display = "Query failed: {query}")]
#[yoshi(kind = "Internal")]
QueryFailed {
query: String,
#[yoshi(shell)]
execution_stats: QueryStats,
},
}
#[derive(Debug)]
struct QueryStats {
duration_ms: u64,
rows_affected: usize,
}
The derive macro automatically creates:
std::fmt::Display implementationstd::error::Error implementationFrom<YourError> for yoshi_std::Yoshi conversionThe macro automatically infers attributes based on naming:
timeout, expired → kind = "Timeout"network, connection → kind = "Network"not_found, missing → kind = "NotFound"std::io::Error fields → source = trueLicensed under either of Apache License, Version 2.0 or MIT License at your option.