From 61950e4c05d8cd4b265f0ab25448f887cb73fd06 Mon Sep 17 00:00:00 2001 From: jgrusewski Date: Sun, 1 Mar 2026 19:39:54 +0100 Subject: [PATCH] refactor: consolidate ErrorSeverity to common crate Three duplicate ErrorSeverity enums (data/error.rs, data/validation.rs, database/error.rs) with variants Low/Medium/High/Critical now use the canonical definition in common::error::ErrorSeverity. Extended common's ErrorSeverity with Low, Medium, High variants (alongside existing Debug, Info, Warn, Error, Critical) and added PartialOrd/Ord derives so both severity models coexist in a single type. Co-Authored-By: Claude Opus 4.6 --- crates/common/src/error.rs | 11 ++++++++++- crates/data/src/error.rs | 26 ++------------------------ crates/data/src/validation.rs | 10 ++-------- crates/database/src/error.rs | 22 ++-------------------- 4 files changed, 16 insertions(+), 53 deletions(-) diff --git a/crates/common/src/error.rs b/crates/common/src/error.rs index 10795f764..e2ea08fd8 100644 --- a/crates/common/src/error.rs +++ b/crates/common/src/error.rs @@ -127,15 +127,21 @@ impl fmt::Display for ErrorCategory { } /// Error severity levels for prioritization and alerting -#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)] #[allow(clippy::module_name_repetitions)] pub enum ErrorSeverity { /// Debug level - for development and troubleshooting Debug, + /// Low severity - informational errors (alias for Info) + Low, /// Info level - informational messages Info, + /// Medium severity - recoverable errors (alias for Warn) + Medium, /// Warning level - potentially problematic situations Warn, + /// High severity - significant errors requiring attention (alias for Error) + High, /// Error level - error conditions that should be addressed Error, /// Critical level - serious error conditions requiring immediate attention @@ -146,8 +152,11 @@ impl fmt::Display for ErrorSeverity { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Self::Debug => write!(f, "DEBUG"), + Self::Low => write!(f, "LOW"), Self::Info => write!(f, "INFO"), + Self::Medium => write!(f, "MEDIUM"), Self::Warn => write!(f, "WARN"), + Self::High => write!(f, "HIGH"), Self::Error => write!(f, "ERROR"), Self::Critical => write!(f, "CRITICAL"), } diff --git a/crates/data/src/error.rs b/crates/data/src/error.rs index 4c0186861..6833b5e0f 100644 --- a/crates/data/src/error.rs +++ b/crates/data/src/error.rs @@ -1,6 +1,6 @@ //! Error types for the data module -use std::fmt; +pub use common::error::ErrorSeverity; use thiserror::Error; /// Result type alias for data module operations @@ -436,29 +436,7 @@ impl DataError { } } -/// Error severity levels -#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] -pub enum ErrorSeverity { - /// Low severity - informational errors - Low, - /// Medium severity - recoverable errors - Medium, - /// High severity - significant errors requiring attention - High, - /// Critical severity - system-threatening errors - Critical, -} - -impl fmt::Display for ErrorSeverity { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - Self::Low => write!(f, "LOW"), - Self::Medium => write!(f, "MEDIUM"), - Self::High => write!(f, "HIGH"), - Self::Critical => write!(f, "CRITICAL"), - } - } -} +// ErrorSeverity is imported from common::error #[cfg(test)] mod tests { diff --git a/crates/data/src/validation.rs b/crates/data/src/validation.rs index 1962ce478..7f7870897 100644 --- a/crates/data/src/validation.rs +++ b/crates/data/src/validation.rs @@ -107,14 +107,8 @@ pub enum ValidationWarningType { InfrequentUpdates, } -/// Error severity levels -#[derive(Debug, Clone, Serialize, Deserialize)] -pub enum ErrorSeverity { - Low, - Medium, - High, - Critical, -} +// ErrorSeverity is imported from common::error (re-exported below) +pub use common::error::ErrorSeverity; /// Data quality metrics #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/crates/database/src/error.rs b/crates/database/src/error.rs index 8525482ff..ed2225aa8 100644 --- a/crates/database/src/error.rs +++ b/crates/database/src/error.rs @@ -1,4 +1,4 @@ -use std::fmt; +pub use common::error::ErrorSeverity; use thiserror::Error; /// Database error types covering all database operations @@ -114,25 +114,7 @@ impl DatabaseError { } } -/// Error severity levels -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub enum ErrorSeverity { - Low, - Medium, - High, - Critical, -} - -impl fmt::Display for ErrorSeverity { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - ErrorSeverity::Low => std::write!(f, "LOW"), - ErrorSeverity::Medium => std::write!(f, "MEDIUM"), - ErrorSeverity::High => std::write!(f, "HIGH"), - ErrorSeverity::Critical => write!(f, "CRITICAL"), - } - } -} +// ErrorSeverity is imported from common::error /// Convert SQLx errors to our domain errors impl From for DatabaseError {