mirror of
https://github.com/pacnpal/Pac-cogs.git
synced 2025-12-20 02:41:06 -05:00
Fix exceptions.py:
- Add CogError with proper details - Add missing error classes to __all__ - Fix formatting and spacing - Add proper docstrings - Fix error class inheritance
This commit is contained in:
@@ -34,24 +34,31 @@ __all__ = [
|
|||||||
'FFmpegError',
|
'FFmpegError',
|
||||||
'DatabaseError',
|
'DatabaseError',
|
||||||
'HealthCheckError',
|
'HealthCheckError',
|
||||||
'TrackingError'
|
'TrackingError',
|
||||||
|
'CommandError',
|
||||||
|
'EventError',
|
||||||
|
'CogError'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class ErrorSeverity(Enum):
|
class ErrorSeverity(Enum):
|
||||||
"""Severity levels for errors"""
|
"""Severity levels for errors"""
|
||||||
|
|
||||||
LOW = auto()
|
LOW = auto()
|
||||||
MEDIUM = auto()
|
MEDIUM = auto()
|
||||||
HIGH = auto()
|
HIGH = auto()
|
||||||
CRITICAL = auto()
|
CRITICAL = auto()
|
||||||
|
|
||||||
|
|
||||||
class ErrorContext:
|
class ErrorContext:
|
||||||
"""Context information for errors"""
|
"""Context information for errors"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
component: str,
|
component: str,
|
||||||
operation: str,
|
operation: str,
|
||||||
details: Optional[Dict[str, Any]] = None,
|
details: Optional[Dict[str, Any]] = None,
|
||||||
severity: ErrorSeverity = ErrorSeverity.MEDIUM
|
severity: ErrorSeverity = ErrorSeverity.MEDIUM,
|
||||||
) -> None:
|
) -> None:
|
||||||
self.component = component
|
self.component = component
|
||||||
self.operation = operation
|
self.operation = operation
|
||||||
@@ -64,114 +71,148 @@ class ErrorContext:
|
|||||||
f"{', '.join(f'{k}={v}' for k, v in self.details.items())}"
|
f"{', '.join(f'{k}={v}' for k, v in self.details.items())}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class VideoArchiverError(Exception):
|
class VideoArchiverError(Exception):
|
||||||
"""Base exception for VideoArchiver errors"""
|
"""Base exception for VideoArchiver errors"""
|
||||||
def __init__(
|
|
||||||
self,
|
def __init__(self, message: str, context: Optional[ErrorContext] = None) -> None:
|
||||||
message: str,
|
|
||||||
context: Optional[ErrorContext] = None
|
|
||||||
) -> None:
|
|
||||||
self.context = context
|
self.context = context
|
||||||
super().__init__(f"{context}: {message}" if context else message)
|
super().__init__(f"{context}: {message}" if context else message)
|
||||||
|
|
||||||
|
|
||||||
class VideoDownloadError(VideoArchiverError):
|
class VideoDownloadError(VideoArchiverError):
|
||||||
"""Error downloading video"""
|
"""Error downloading video"""
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class VideoProcessingError(VideoArchiverError):
|
class VideoProcessingError(VideoArchiverError):
|
||||||
"""Error processing video"""
|
"""Error processing video"""
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class VideoVerificationError(VideoArchiverError):
|
class VideoVerificationError(VideoArchiverError):
|
||||||
"""Error verifying video"""
|
"""Error verifying video"""
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class VideoUploadError(VideoArchiverError):
|
class VideoUploadError(VideoArchiverError):
|
||||||
"""Error uploading video"""
|
"""Error uploading video"""
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class VideoCleanupError(VideoArchiverError):
|
class VideoCleanupError(VideoArchiverError):
|
||||||
"""Error cleaning up video files"""
|
"""Error cleaning up video files"""
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class FileCleanupError(VideoArchiverError):
|
class FileCleanupError(VideoArchiverError):
|
||||||
"""Error cleaning up files"""
|
"""Error cleaning up files"""
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class ConfigurationError(VideoArchiverError):
|
class ConfigurationError(VideoArchiverError):
|
||||||
"""Error in configuration"""
|
"""Error in configuration"""
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class PermissionError(VideoArchiverError):
|
class PermissionError(VideoArchiverError):
|
||||||
"""Error with file permissions"""
|
"""Error with file permissions"""
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class NetworkError(VideoArchiverError):
|
class NetworkError(VideoArchiverError):
|
||||||
"""Error with network operations"""
|
"""Error with network operations"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
message: str,
|
message: str,
|
||||||
url: Optional[str] = None,
|
url: Optional[str] = None,
|
||||||
status_code: Optional[int] = None,
|
status_code: Optional[int] = None,
|
||||||
context: Optional[ErrorContext] = None
|
context: Optional[ErrorContext] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
self.url = url
|
self.url = url
|
||||||
self.status_code = status_code
|
self.status_code = status_code
|
||||||
details = f" (URL: {url}" + (f", Status: {status_code})" if status_code else ")")
|
details = f" (URL: {url}" + (
|
||||||
|
f", Status: {status_code})" if status_code else ")"
|
||||||
|
)
|
||||||
super().__init__(message + details, context)
|
super().__init__(message + details, context)
|
||||||
|
|
||||||
|
|
||||||
class ResourceError(VideoArchiverError):
|
class ResourceError(VideoArchiverError):
|
||||||
"""Error with system resources"""
|
"""Error with system resources"""
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class QueueError(VideoArchiverError):
|
class QueueError(VideoArchiverError):
|
||||||
"""Error with queue operations"""
|
"""Error with queue operations"""
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class ComponentError(VideoArchiverError):
|
class ComponentError(VideoArchiverError):
|
||||||
"""Error with component initialization or cleanup"""
|
"""Error with component initialization or cleanup"""
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class DiscordAPIError(VideoArchiverError):
|
class DiscordAPIError(VideoArchiverError):
|
||||||
"""Error with Discord API operations"""
|
"""Error with Discord API operations"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
message: str,
|
message: str,
|
||||||
status_code: Optional[int] = None,
|
status_code: Optional[int] = None,
|
||||||
context: Optional[ErrorContext] = None
|
context: Optional[ErrorContext] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
self.status_code = status_code
|
self.status_code = status_code
|
||||||
details = f" (Status: {status_code})" if status_code else ""
|
details = f" (Status: {status_code})" if status_code else ""
|
||||||
super().__init__(f"Discord API Error: {message}{details}", context)
|
super().__init__(f"Discord API Error: {message}{details}", context)
|
||||||
|
|
||||||
|
|
||||||
class ResourceExhaustedError(VideoArchiverError):
|
class ResourceExhaustedError(VideoArchiverError):
|
||||||
"""Error when system resources are exhausted"""
|
"""Error when system resources are exhausted"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
message: str,
|
message: str,
|
||||||
resource_type: Optional[str] = None,
|
resource_type: Optional[str] = None,
|
||||||
context: Optional[ErrorContext] = None
|
context: Optional[ErrorContext] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
self.resource_type = resource_type
|
self.resource_type = resource_type
|
||||||
details = f" (Type: {resource_type})" if resource_type else ""
|
details = f" (Type: {resource_type})" if resource_type else ""
|
||||||
super().__init__(f"Resource exhausted: {message}{details}", context)
|
super().__init__(f"Resource exhausted: {message}{details}", context)
|
||||||
|
|
||||||
|
|
||||||
class ProcessingError(VideoArchiverError):
|
class ProcessingError(VideoArchiverError):
|
||||||
"""Error during video processing"""
|
"""Error during video processing"""
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class CleanupError(VideoArchiverError):
|
class CleanupError(VideoArchiverError):
|
||||||
"""Error during cleanup operations"""
|
"""Error during cleanup operations"""
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class FileOperationError(VideoArchiverError):
|
class FileOperationError(VideoArchiverError):
|
||||||
"""Error during file operations"""
|
"""Error during file operations"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
message: str,
|
message: str,
|
||||||
path: Optional[str] = None,
|
path: Optional[str] = None,
|
||||||
operation: Optional[str] = None,
|
operation: Optional[str] = None,
|
||||||
context: Optional[ErrorContext] = None
|
context: Optional[ErrorContext] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
self.path = path
|
self.path = path
|
||||||
self.operation = operation
|
self.operation = operation
|
||||||
@@ -183,59 +224,74 @@ class FileOperationError(VideoArchiverError):
|
|||||||
details_str = f" ({', '.join(details)})" if details else ""
|
details_str = f" ({', '.join(details)})" if details else ""
|
||||||
super().__init__(f"File operation error: {message}{details_str}", context)
|
super().__init__(f"File operation error: {message}{details_str}", context)
|
||||||
|
|
||||||
# New exceptions for processor components
|
|
||||||
class ProcessorError(VideoArchiverError):
|
class ProcessorError(VideoArchiverError):
|
||||||
"""Error in video processor operations"""
|
"""Error in video processor operations"""
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class ValidationError(VideoArchiverError):
|
class ValidationError(VideoArchiverError):
|
||||||
"""Error in message or content validation"""
|
"""Error in message or content validation"""
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class DisplayError(VideoArchiverError):
|
class DisplayError(VideoArchiverError):
|
||||||
"""Error in status display operations"""
|
"""Error in status display operations"""
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class URLExtractionError(VideoArchiverError):
|
class URLExtractionError(VideoArchiverError):
|
||||||
"""Error extracting URLs from content"""
|
"""Error extracting URLs from content"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
message: str,
|
message: str,
|
||||||
url: Optional[str] = None,
|
url: Optional[str] = None,
|
||||||
context: Optional[ErrorContext] = None
|
context: Optional[ErrorContext] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
self.url = url
|
self.url = url
|
||||||
details = f" (URL: {url})" if url else ""
|
details = f" (URL: {url})" if url else ""
|
||||||
super().__init__(f"URL extraction error: {message}{details}", context)
|
super().__init__(f"URL extraction error: {message}{details}", context)
|
||||||
|
|
||||||
|
|
||||||
class MessageHandlerError(VideoArchiverError):
|
class MessageHandlerError(VideoArchiverError):
|
||||||
"""Error in message handling operations"""
|
"""Error in message handling operations"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
message: str,
|
message: str,
|
||||||
message_id: Optional[int] = None,
|
message_id: Optional[int] = None,
|
||||||
context: Optional[ErrorContext] = None
|
context: Optional[ErrorContext] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
self.message_id = message_id
|
self.message_id = message_id
|
||||||
details = f" (Message ID: {message_id})" if message_id else ""
|
details = f" (Message ID: {message_id})" if message_id else ""
|
||||||
super().__init__(f"Message handler error: {message}{details}", context)
|
super().__init__(f"Message handler error: {message}{details}", context)
|
||||||
|
|
||||||
|
|
||||||
class QueueHandlerError(VideoArchiverError):
|
class QueueHandlerError(VideoArchiverError):
|
||||||
"""Error in queue handling operations"""
|
"""Error in queue handling operations"""
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class QueueProcessorError(VideoArchiverError):
|
class QueueProcessorError(VideoArchiverError):
|
||||||
"""Error in queue processing operations"""
|
"""Error in queue processing operations"""
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class FFmpegError(VideoArchiverError):
|
class FFmpegError(VideoArchiverError):
|
||||||
"""Error in FFmpeg operations"""
|
"""Error in FFmpeg operations"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
message: str,
|
message: str,
|
||||||
command: Optional[str] = None,
|
command: Optional[str] = None,
|
||||||
exit_code: Optional[int] = None,
|
exit_code: Optional[int] = None,
|
||||||
context: Optional[ErrorContext] = None
|
context: Optional[ErrorContext] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
self.command = command
|
self.command = command
|
||||||
self.exit_code = exit_code
|
self.exit_code = exit_code
|
||||||
@@ -247,38 +303,44 @@ class FFmpegError(VideoArchiverError):
|
|||||||
details_str = f" ({', '.join(details)})" if details else ""
|
details_str = f" ({', '.join(details)})" if details else ""
|
||||||
super().__init__(f"FFmpeg error: {message}{details_str}", context)
|
super().__init__(f"FFmpeg error: {message}{details_str}", context)
|
||||||
|
|
||||||
|
|
||||||
class DatabaseError(VideoArchiverError):
|
class DatabaseError(VideoArchiverError):
|
||||||
"""Error in database operations"""
|
"""Error in database operations"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
message: str,
|
message: str,
|
||||||
query: Optional[str] = None,
|
query: Optional[str] = None,
|
||||||
context: Optional[ErrorContext] = None
|
context: Optional[ErrorContext] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
self.query = query
|
self.query = query
|
||||||
details = f" (Query: {query})" if query else ""
|
details = f" (Query: {query})" if query else ""
|
||||||
super().__init__(f"Database error: {message}{details}", context)
|
super().__init__(f"Database error: {message}{details}", context)
|
||||||
|
|
||||||
|
|
||||||
class HealthCheckError(VideoArchiverError):
|
class HealthCheckError(VideoArchiverError):
|
||||||
"""Error in health check operations"""
|
"""Error in health check operations"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
message: str,
|
message: str,
|
||||||
component: Optional[str] = None,
|
component: Optional[str] = None,
|
||||||
context: Optional[ErrorContext] = None
|
context: Optional[ErrorContext] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
self.component = component
|
self.component = component
|
||||||
details = f" (Component: {component})" if component else ""
|
details = f" (Component: {component})" if component else ""
|
||||||
super().__init__(f"Health check error: {message}{details}", context)
|
super().__init__(f"Health check error: {message}{details}", context)
|
||||||
|
|
||||||
|
|
||||||
class TrackingError(VideoArchiverError):
|
class TrackingError(VideoArchiverError):
|
||||||
"""Error in progress tracking operations"""
|
"""Error in progress tracking operations"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
message: str,
|
message: str,
|
||||||
operation: Optional[str] = None,
|
operation: Optional[str] = None,
|
||||||
item_id: Optional[str] = None,
|
item_id: Optional[str] = None,
|
||||||
context: Optional[ErrorContext] = None
|
context: Optional[ErrorContext] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
self.operation = operation
|
self.operation = operation
|
||||||
self.item_id = item_id
|
self.item_id = item_id
|
||||||
@@ -289,3 +351,27 @@ class TrackingError(VideoArchiverError):
|
|||||||
details.append(f"Item ID: {item_id}")
|
details.append(f"Item ID: {item_id}")
|
||||||
details_str = f" ({', '.join(details)})" if details else ""
|
details_str = f" ({', '.join(details)})" if details else ""
|
||||||
super().__init__(f"Progress tracking error: {message}{details_str}", context)
|
super().__init__(f"Progress tracking error: {message}{details_str}", context)
|
||||||
|
|
||||||
|
|
||||||
|
class CommandError(VideoArchiverError):
|
||||||
|
"""Error in command execution"""
|
||||||
|
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class EventError(VideoArchiverError):
|
||||||
|
"""Error in event handling"""
|
||||||
|
|
||||||
|
pass
|
||||||
|
|
||||||
|
class CogError(VideoArchiverError):
|
||||||
|
"""Error in cog operations"""
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
message: str,
|
||||||
|
cog_name: Optional[str] = None,
|
||||||
|
context: Optional[ErrorContext] = None
|
||||||
|
) -> None:
|
||||||
|
self.cog_name = cog_name
|
||||||
|
details = f" (Cog: {cog_name})" if cog_name else ""
|
||||||
|
super().__init__(f"Cog error: {message}{details}", context)
|
||||||
|
|||||||
Reference in New Issue
Block a user