alkahest_cas/errors/mod.rs
1//! Structured error types with stable diagnostic codes and remediation hints.
2//!
3//! The canonical list of every code is in [`codes::REGISTRY`].
4//!
5//! # V1-3 — Full structured error hierarchy
6//!
7//! Every public error type in `alkahest-core` implements [`AlkahestError`], which
8//! provides three machine-readable fields in addition to the `Display` message:
9//!
10//! - **`code()`** — a stable `&'static str` like `"E-POLY-001"`. Suitable for
11//! `match` in user code and dictionary look-up in tool integrations.
12//! - **`remediation()`** — a human-readable fix suggestion, or `None` if the
13//! error is self-explanatory.
14//! - **`span()`** — optional `(start, end)` byte offsets into a source string
15//! for IDE diagnostics. `None` until the parser is integrated.
16
17pub mod codes;
18
19/// Core trait shared by every `alkahest-core` error type.
20pub trait AlkahestError: std::error::Error {
21 /// Stable diagnostic code, e.g. `"E-DIFF-001"`.
22 fn code(&self) -> &'static str;
23
24 /// Optional human-readable fix suggestion.
25 fn remediation(&self) -> Option<&'static str> {
26 None
27 }
28
29 /// Optional source span `(start_byte, end_byte)` within the input text.
30 fn span(&self) -> Option<(usize, usize)> {
31 None
32 }
33}