Source code

Download source archive ↓

src/pypdf/errors.py

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