Coverage for src/epublib/exceptions.py: 100%
12 statements
« prev ^ index » next coverage.py v7.10.7, created at 2025-10-06 16:09 -0300
« prev ^ index » next coverage.py v7.10.7, created at 2025-10-06 16:09 -0300
1import warnings
4class EPUBWarning(Warning):
5 """Base warning for EPUBLib."""
8class EPUBError(Exception):
9 """Base error for EPUBLib."""
11 @classmethod
12 def missing_ncx(cls, calling: object, method: str, arg: str = "reset_ncx"):
13 return cls(
14 f"'{calling.__class__.__name__}.{method}' received '{arg}=True' "
15 "but there is no NCX file in the book. Create the NCX "
16 f"file with '{calling.__class__.__name__}.create_ncx' or use "
17 f"a falsy value for the '{arg}' parameter"
18 )
21class NotEPUBError(EPUBError):
22 """The file is not an EPUB file."""
24 def __init__(self, msg: str, *args: object) -> None:
25 super().__init__(f"File is not epub: {msg}", *args)
28class ClosedEPUBError(EPUBError):
29 """An operation was attempted on a closed EPUB file."""
32def warn(warning: str, cls: type[EPUBWarning] = EPUBWarning):
33 warnings.warn(warning, cls)