Coverage for src/qdrant_loader/core/file_conversion/exceptions.py: 100%
32 statements
« prev ^ index » next coverage.py v7.10.6, created at 2025-09-08 06:05 +0000
« prev ^ index » next coverage.py v7.10.6, created at 2025-09-08 06:05 +0000
1"""Custom exceptions for file conversion operations."""
4class FileConversionError(Exception):
5 """Base exception for file conversion errors."""
7 def __init__(
8 self,
9 message: str,
10 file_path: str | None = None,
11 file_type: str | None = None,
12 ):
13 """Initialize the exception.
15 Args:
16 message: Error message
17 file_path: Path to the file that failed conversion
18 file_type: Type of file that failed conversion
19 """
20 super().__init__(message)
21 self.file_path = file_path
22 self.file_type = file_type
25class UnsupportedFileTypeError(FileConversionError):
26 """Exception raised when file type is not supported for conversion."""
28 def __init__(self, file_type: str, file_path: str | None = None):
29 """Initialize the exception.
31 Args:
32 file_type: The unsupported file type
33 file_path: Path to the unsupported file
34 """
35 message = f"File type '{file_type}' is not supported for conversion"
36 super().__init__(message, file_path, file_type)
39class FileSizeExceededError(FileConversionError):
40 """Exception raised when file size exceeds the maximum allowed size."""
42 def __init__(self, file_size: int, max_size: int, file_path: str | None = None):
43 """Initialize the exception.
45 Args:
46 file_size: Actual file size in bytes
47 max_size: Maximum allowed file size in bytes
48 file_path: Path to the oversized file
49 """
50 message = (
51 f"File size {file_size} bytes exceeds maximum allowed size {max_size} bytes"
52 )
53 super().__init__(message, file_path)
54 self.file_size = file_size
55 self.max_size = max_size
58class ConversionTimeoutError(FileConversionError):
59 """Exception raised when file conversion times out."""
61 def __init__(self, timeout: int, file_path: str | None = None):
62 """Initialize the exception.
64 Args:
65 timeout: Timeout duration in seconds
66 file_path: Path to the file that timed out
67 """
68 message = f"File conversion timed out after {timeout} seconds"
69 super().__init__(message, file_path)
70 self.timeout = timeout
73class MarkItDownError(FileConversionError):
74 """Exception raised when MarkItDown library fails."""
76 def __init__(
77 self,
78 original_error: Exception,
79 file_path: str | None = None,
80 file_type: str | None = None,
81 ):
82 """Initialize the exception.
84 Args:
85 original_error: The original exception from MarkItDown
86 file_path: Path to the file that failed conversion
87 file_type: Type of file that failed conversion
88 """
89 message = f"MarkItDown conversion failed: {str(original_error)}"
90 super().__init__(message, file_path, file_type)
91 self.original_error = original_error
94class FileAccessError(FileConversionError):
95 """Exception raised when file cannot be accessed or read."""
97 def __init__(self, file_path: str, original_error: Exception | None = None):
98 """Initialize the exception.
100 Args:
101 file_path: Path to the inaccessible file
102 original_error: The original exception that caused the access error
103 """
104 message = f"Cannot access file: {file_path}"
105 if original_error:
106 message += f" - {str(original_error)}"
107 super().__init__(message, file_path)
108 self.original_error = original_error