Coverage for src/qdrant_loader/core/file_conversion/exceptions.py: 100%
33 statements
« prev ^ index » next coverage.py v7.8.2, created at 2025-06-04 05:50 +0000
« prev ^ index » next coverage.py v7.8.2, created at 2025-06-04 05:50 +0000
1"""Custom exceptions for file conversion operations."""
3from typing import Optional
6class FileConversionError(Exception):
7 """Base exception for file conversion errors."""
9 def __init__(
10 self,
11 message: str,
12 file_path: Optional[str] = None,
13 file_type: Optional[str] = None,
14 ):
15 """Initialize the exception.
17 Args:
18 message: Error message
19 file_path: Path to the file that failed conversion
20 file_type: Type of file that failed conversion
21 """
22 super().__init__(message)
23 self.file_path = file_path
24 self.file_type = file_type
27class UnsupportedFileTypeError(FileConversionError):
28 """Exception raised when file type is not supported for conversion."""
30 def __init__(self, file_type: str, file_path: Optional[str] = None):
31 """Initialize the exception.
33 Args:
34 file_type: The unsupported file type
35 file_path: Path to the unsupported file
36 """
37 message = f"File type '{file_type}' is not supported for conversion"
38 super().__init__(message, file_path, file_type)
41class FileSizeExceededError(FileConversionError):
42 """Exception raised when file size exceeds the maximum allowed size."""
44 def __init__(self, file_size: int, max_size: int, file_path: Optional[str] = None):
45 """Initialize the exception.
47 Args:
48 file_size: Actual file size in bytes
49 max_size: Maximum allowed file size in bytes
50 file_path: Path to the oversized file
51 """
52 message = (
53 f"File size {file_size} bytes exceeds maximum allowed size {max_size} bytes"
54 )
55 super().__init__(message, file_path)
56 self.file_size = file_size
57 self.max_size = max_size
60class ConversionTimeoutError(FileConversionError):
61 """Exception raised when file conversion times out."""
63 def __init__(self, timeout: int, file_path: Optional[str] = None):
64 """Initialize the exception.
66 Args:
67 timeout: Timeout duration in seconds
68 file_path: Path to the file that timed out
69 """
70 message = f"File conversion timed out after {timeout} seconds"
71 super().__init__(message, file_path)
72 self.timeout = timeout
75class MarkItDownError(FileConversionError):
76 """Exception raised when MarkItDown library fails."""
78 def __init__(
79 self,
80 original_error: Exception,
81 file_path: Optional[str] = None,
82 file_type: Optional[str] = None,
83 ):
84 """Initialize the exception.
86 Args:
87 original_error: The original exception from MarkItDown
88 file_path: Path to the file that failed conversion
89 file_type: Type of file that failed conversion
90 """
91 message = f"MarkItDown conversion failed: {str(original_error)}"
92 super().__init__(message, file_path, file_type)
93 self.original_error = original_error
96class FileAccessError(FileConversionError):
97 """Exception raised when file cannot be accessed or read."""
99 def __init__(self, file_path: str, original_error: Optional[Exception] = None):
100 """Initialize the exception.
102 Args:
103 file_path: Path to the inaccessible file
104 original_error: The original exception that caused the access error
105 """
106 message = f"Cannot access file: {file_path}"
107 if original_error:
108 message += f" - {str(original_error)}"
109 super().__init__(message, file_path)
110 self.original_error = original_error