use error_engine::{Catalog, Engine, EngineDiagnostic, Severity};
use error_engine::thiserror::Error;
#[derive(Debug, Error)]
enum AppError {
#[error("config not found")]
ConfigNotFound { path: String },
}
impl EngineDiagnostic for AppError {
fn code(&self) -> &'static str {
match self {
AppError::ConfigNotFound { .. } => "CONFIG_NOT_FOUND",
}
}
fn severity(&self) -> Severity {
Severity::Error
}
fn context(&self) -> Vec<(&'static str, String)> {
match self {
AppError::ConfigNotFound { path } => vec![("path", path.clone())],
}
}
}
fn main() -> anyhow::Result<()> {
tracing_subscriber::fmt::init();
let catalog = Catalog::load_or_fallback("examples/errors.toml");
let engine = Engine::new(catalog);
let err = AppError::ConfigNotFound { path: "/etc/app.toml".into() };
println!("{}", engine.message(&err));
engine.log(&err);
Ok(())
}