Coverage for src/pdfbaker/errors.py: 100%

13 statements  

« prev     ^ index     » next       coverage.py v7.8.0, created at 2025-04-20 04:55 +1200

1"""pdfbaker exceptions.""" 

2 

3from pathlib import Path 

4 

5__all__ = [ 

6 "ConfigurationError", 

7 "PDFBakerError", 

8 "PDFCombineError", 

9 "PDFCompressionError", 

10 "SVGConversionError", 

11 "SVGTemplateError", 

12] 

13 

14 

15class PDFBakerError(Exception): 

16 """Base exception for PDF baking errors.""" 

17 

18 

19class ConfigurationError(PDFBakerError): 

20 """Failed to load or parse configuration.""" 

21 

22 

23class PDFCombineError(PDFBakerError): 

24 """Failed to combine PDFs.""" 

25 

26 

27class PDFCompressionError(PDFBakerError): 

28 """Failed to compress PDF.""" 

29 

30 

31class SVGConversionError(PDFBakerError): 

32 """Failed to convert SVG to PDF.""" 

33 

34 def __init__( 

35 self, svg_path: str | Path, backend: str, cause: str | None = None 

36 ) -> None: 

37 self.svg_path = svg_path 

38 self.backend = backend 

39 self.cause = cause 

40 super().__init__(f"Failed to convert {svg_path} using {backend}: {cause}") 

41 

42 

43class SVGTemplateError(PDFBakerError): 

44 """Failed to load or render an SVG template."""