Arag / app /exceptions /ingestion.py
AuthorBot
Restructure project for HF Spaces deployment
772f852
Raw
History Blame Contribute Delete
1.94 kB
"""Author RAG Chatbot SaaS — Document Ingestion Exceptions."""
from app.exceptions.base import AppException
class ParseError(AppException):
"""File could not be parsed into text."""
def __init__(self, filename: str, reason: str) -> None:
super().__init__(f"Failed to parse '{filename}': {reason}")
self.filename = filename
self.reason = reason
class DuplicateFileError(AppException):
"""A file with the same content hash already exists for this author."""
def __init__(self, existing_title: str) -> None:
super().__init__(f"This file was already uploaded as '{existing_title}'")
self.existing_title = existing_title
class UnsupportedFormatError(AppException):
"""File format is not supported by the ingestion pipeline."""
SUPPORTED = ["pdf", "epub", "docx", "txt"]
def __init__(self, extension: str) -> None:
supported = ", ".join(self.SUPPORTED).upper()
super().__init__(f"'{extension}' is not supported. Supported formats: {supported}")
self.extension = extension
class FileTooLargeError(AppException):
"""Uploaded file exceeds the maximum allowed size."""
def __init__(self, size_mb: float, max_mb: int) -> None:
super().__init__(f"File size {size_mb:.1f}MB exceeds the {max_mb}MB limit")
self.size_mb = size_mb
self.max_mb = max_mb
class EmptyFileError(AppException):
"""Uploaded file contains no content."""
def __init__(self) -> None:
super().__init__("The uploaded file is empty")
class CorruptedFileError(AppException):
"""File content is corrupted or unreadable."""
def __init__(self, filename: str) -> None:
super().__init__(f"'{filename}' appears to be corrupted. Try re-exporting from your editor.")
self.filename = filename
# Alias kept for backwards-compatibility with tests and documents.py
UnsupportedFileTypeError = UnsupportedFormatError