feat: Implement unified configuration management system
Consolidates scattered configuration patterns across TDDAI, Gitea, and MarkiTect into a unified, maintainable system addressing issue #22. Key improvements: - Created centralized config/ module with base classes and utilities - Eliminated duplicate load_dotenv_file() functions - Standardized environment variables with MARKITECT_ prefix - Implemented comprehensive validation with helpful error messages - Maintained full backward compatibility with existing TDDAI config Architecture: - BaseConfig: Abstract base with common functionality - MarkitectConfig: Main configuration class with legacy support - Compatibility layer: TddaiConfigCompat and GiteaConfigCompat wrappers - Unified error handling: ConfigurationError hierarchy All existing tests pass without modification, ensuring seamless transition. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
73
config/exceptions.py
Normal file
73
config/exceptions.py
Normal file
@@ -0,0 +1,73 @@
|
||||
"""
|
||||
Configuration-specific exceptions.
|
||||
|
||||
Provides a unified exception hierarchy for all configuration-related errors
|
||||
across the MarkiTect project.
|
||||
"""
|
||||
|
||||
from typing import Optional, Dict, Any
|
||||
|
||||
|
||||
class ConfigurationError(Exception):
|
||||
"""Base exception for configuration-related errors.
|
||||
|
||||
Provides enhanced error context and troubleshooting guidance.
|
||||
|
||||
Args:
|
||||
message: Human-readable error description
|
||||
field: Specific configuration field that caused the error
|
||||
value: The invalid value (if applicable)
|
||||
suggestion: Suggested fix for the error
|
||||
context: Additional context information
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
message: str,
|
||||
field: Optional[str] = None,
|
||||
value: Optional[Any] = None,
|
||||
suggestion: Optional[str] = None,
|
||||
context: Optional[Dict[str, Any]] = None):
|
||||
super().__init__(message)
|
||||
self.field = field
|
||||
self.value = value
|
||||
self.suggestion = suggestion
|
||||
self.context = context or {}
|
||||
|
||||
def __str__(self) -> str:
|
||||
"""Enhanced string representation with troubleshooting guidance."""
|
||||
parts = [super().__str__()]
|
||||
|
||||
if self.field:
|
||||
parts.append(f"Field: {self.field}")
|
||||
|
||||
if self.value is not None:
|
||||
parts.append(f"Value: {self.value}")
|
||||
|
||||
if self.suggestion:
|
||||
parts.append(f"Suggestion: {self.suggestion}")
|
||||
|
||||
return " | ".join(parts)
|
||||
|
||||
|
||||
class ConfigValidationError(ConfigurationError):
|
||||
"""Configuration validation specific errors.
|
||||
|
||||
Raised when configuration values fail validation checks.
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
class ConfigFileError(ConfigurationError):
|
||||
"""Configuration file related errors.
|
||||
|
||||
Raised when configuration files cannot be read, parsed, or found.
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
class EnvironmentVariableError(ConfigurationError):
|
||||
"""Environment variable related errors.
|
||||
|
||||
Raised when required environment variables are missing or invalid.
|
||||
"""
|
||||
pass
|
||||
Reference in New Issue
Block a user