Skip to main content

SanthErrorContract

Trait SanthErrorContract 

Source
pub trait SanthErrorContract: Error {
    // Required methods
    fn error_code(&self) -> &'static str;
    fn fix_hint(&self) -> Cow<'_, str>;

    // Provided methods
    fn title(&self) -> Cow<'_, str> { ... }
    fn context(&self) -> Vec<(Cow<'static, str>, String)> { ... }
    fn location(&self) -> Option<&ErrorLocation> { ... }
    fn actionable_message(&self) -> String { ... }
}
Expand description

The Santh error contract: every Santh error answers the same questions - which error it is (error_code), how to fix it (fix_hint, always starting with "Fix: "), and what failed (title via Display) - plus optional context and location.

Domain crates keep their own error enums - their variants are their behavior - and implement this trait to join the contract. They do not fold their variants into SanthError: the trait gives one consistent surface across the fleet without duplicating each crate’s API upward. A thiserror-style enum needs only error_code and fix_hint; the title comes from Display and the rest defaults sensibly.

SanthError implements this trait, so the canonical type and every domain error render identically via actionable_message.

Required Methods§

Source

fn error_code(&self) -> &'static str

Stable, machine-readable error code, e.g. "KEYHOG-E001".

Source

fn fix_hint(&self) -> Cow<'_, str>

The actionable fix hint. Must start with "Fix: ".

Provided Methods§

Source

fn title(&self) -> Cow<'_, str>

One-line human-readable title. Defaults to the Display output, which is correct for thiserror-style enums whose Display is the short message.

Source

fn context(&self) -> Vec<(Cow<'static, str>, String)>

Key-value diagnostic context. Empty by default.

Source

fn location(&self) -> Option<&ErrorLocation>

Optional source or configuration location. None by default.

Source

fn actionable_message(&self) -> String

Actionable, human-readable message: title, fix, context, location, and the source chain, with secrets redacted. The default matches SanthError exactly; override only for a custom layout.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§