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 <noreply@anthropic.com>
This commit is contained in:
jgrusewski
2026-03-01 19:39:54 +01:00
parent 08a0e1d036
commit 61950e4c05
4 changed files with 16 additions and 53 deletions

View File

@@ -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"),
}

View File

@@ -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 {

View File

@@ -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)]

View File

@@ -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<sqlx::Error> for DatabaseError {