Expand description
The klauthed error kernel.
This crate deliberately holds no error types — those live with the domains
that raise them (ConfigError in klauthed-core, DataError in
klauthed-data, …). Instead it defines the shared contract every klauthed
error implements, so the whole system classifies, codes, and surfaces errors
the same way:
ErrorCategory— coarse classification driving HTTP status / retryability.ErrorCode— a stabledomain.reasoncode for logs and API responses.DomainError— the trait each concrete error type implements.
It has zero required dependencies (enable the serde feature to serialize
codes/categories), so everything can depend on it without pulling weight and
without creating cycles: types stay home, only the contract is shared.
use klauthed_error::{DomainError, ErrorCategory, ErrorCode};
#[derive(Debug)]
struct WidgetMissing(String);
impl std::fmt::Display for WidgetMissing {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "widget {} not found", self.0)
}
}
impl std::error::Error for WidgetMissing {}
impl DomainError for WidgetMissing {
fn category(&self) -> ErrorCategory { ErrorCategory::NotFound }
fn code(&self) -> ErrorCode { ErrorCode::new("widget.not_found") }
}
let err = WidgetMissing("w-1".into());
assert_eq!(err.http_status(), 404);
assert!(!err.is_retryable());Structs§
- Error
Code - A stable, machine-readable error code for logs and API responses.
Enums§
- Error
Category - A coarse classification every klauthed error maps onto.
Traits§
- Domain
Error - The contract every klauthed error type implements.