errors.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. """
  2. All errors/exceptions pypdf raises and all of the warnings it uses.
  3. Please note that broken PDF files might cause other Exceptions.
  4. """
  5. class DeprecationError(Exception):
  6. """Raised when a deprecated feature is used."""
  7. class DependencyError(Exception):
  8. """
  9. Raised when a required dependency (a library or module that pypdf depends on)
  10. is not available or cannot be imported.
  11. """
  12. class PyPdfError(Exception):
  13. """Base class for all exceptions raised by pypdf."""
  14. class PdfReadError(PyPdfError):
  15. """Raised when there is an issue reading a PDF file."""
  16. class PageSizeNotDefinedError(PyPdfError):
  17. """Raised when the page size of a PDF document is not defined."""
  18. class PdfReadWarning(UserWarning):
  19. """Issued when there is a potential issue reading a PDF file, but it can still be read."""
  20. class PdfStreamError(PdfReadError):
  21. """Raised when there is an issue reading the stream of data in a PDF file."""
  22. class ParseError(PyPdfError):
  23. """
  24. Raised when there is an issue parsing (analyzing and understanding the
  25. structure and meaning of) a PDF file.
  26. """
  27. class FileNotDecryptedError(PdfReadError):
  28. """
  29. Raised when a PDF file that has been encrypted
  30. (meaning it requires a password to be accessed) has not been successfully
  31. decrypted.
  32. """
  33. class WrongPasswordError(FileNotDecryptedError):
  34. """Raised when the wrong password is used to try to decrypt an encrypted PDF file."""
  35. class EmptyFileError(PdfReadError):
  36. """Raised when a PDF file is empty or has no content."""
  37. class EmptyImageDataError(PyPdfError):
  38. """Raised when trying to process an image that has no data."""
  39. STREAM_TRUNCATED_PREMATURELY = "Stream has ended unexpectedly"
  40. class LimitReachedError(PyPdfError):
  41. """Raised when a limit is reached."""
  42. class XmpDocumentError(PyPdfError, RuntimeError):
  43. """Raised when the XMP XML document context is invalid or missing."""