Skip to main content

Crate klauthed_error

Crate klauthed_error 

Source
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 stable domain.reason code 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§

ErrorCode
A stable, machine-readable error code for logs and API responses.

Enums§

ErrorCategory
A coarse classification every klauthed error maps onto.

Traits§

DomainError
The contract every klauthed error type implements.