Coverage for oarepo_c4gh/exceptions.py: 100%
22 statements
« prev ^ index » next coverage.py v7.10.2, created at 2025-08-07 12:05 +0000
« prev ^ index » next coverage.py v7.10.2, created at 2025-08-07 12:05 +0000
1"""This module defines all the exceptions the Crypt4GH library may
2produce.
4"""
7class Crypt4GHException(Exception):
8 """Basic Crypt4GH exception from which all exceptions must be
9 derived. This exception must not be used directly.
11 """
13 def __init__(self, ecode: str, message: str) -> None:
14 """Initializes the internal exception code. This is used by
15 derived exceptions to specify the machine-readable exception
16 code.
18 Parameters:
19 ecode: internal machine-readable string identifying the exception
20 message: a descriptive message about the problem
22 """
23 super().__init__(message)
24 self._code = ecode
26 @property
27 def code(self) -> str:
28 """The machine-readable exception code provided as instance
29 exception property for convenience.
31 """
32 return self._code
35class Crypt4GHKeyException(Crypt4GHException):
36 """An exception for any problems related to the user-provided
37 cryptographic keys and not the Crypt4GH containers themselves.
39 """
41 def __init__(self, message: str) -> None:
42 """Initializes the key exception.
44 Parameters:
45 message: a descriptive message about the problem
46 """
47 super().__init__("KEY", message)
50class Crypt4GHHeaderException(Crypt4GHException):
51 """An exception related to Crypt4GH header processing problem."""
53 def __init__(self, message: str) -> None:
54 """Initializes the header exception.
56 Parameters:
57 message: a descriptive message about the problem
58 """
59 super().__init__("HEADER", message)
62class Crypt4GHHeaderPacketException(Crypt4GHException):
63 """An exception related to particular Crypt4GH header packet
64 processing problem.
66 """
68 def __init__(self, message: str) -> None:
69 """Initializes the header packet exception.
71 Parameters:
72 message: a descriptive message about the problem
73 """
74 super().__init__("HEADERPACKET", message)
77class Crypt4GHDEKException(Crypt4GHException):
78 """Base exception raised when something goes wrong with Data
79 Encryption Key(s).
81 """
83 def __init__(self, message: str) -> None:
84 """Initializes the DEK exception.
86 Parameters:
87 message: a descriptive message about the problem
89 """
90 super().__init__("DEK", message)
93class Crypt4GHProcessedException(Crypt4GHException):
94 """An exception for signalling the container cannot be processed
95 again from the beginning.
97 """
99 def __init__(self, message: str) -> None:
100 """Initializes the Processed exception.
102 Parameters:
103 message: a decriptive message about the problem
105 """
106 super().__init__("PROCESSED", message)