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

1"""This module defines all the exceptions the Crypt4GH library may 

2produce. 

3 

4""" 

5 

6 

7class Crypt4GHException(Exception): 

8 """Basic Crypt4GH exception from which all exceptions must be 

9 derived. This exception must not be used directly. 

10 

11 """ 

12 

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. 

17 

18 Parameters: 

19 ecode: internal machine-readable string identifying the exception 

20 message: a descriptive message about the problem 

21 

22 """ 

23 super().__init__(message) 

24 self._code = ecode 

25 

26 @property 

27 def code(self) -> str: 

28 """The machine-readable exception code provided as instance 

29 exception property for convenience. 

30 

31 """ 

32 return self._code 

33 

34 

35class Crypt4GHKeyException(Crypt4GHException): 

36 """An exception for any problems related to the user-provided 

37 cryptographic keys and not the Crypt4GH containers themselves. 

38 

39 """ 

40 

41 def __init__(self, message: str) -> None: 

42 """Initializes the key exception. 

43 

44 Parameters: 

45 message: a descriptive message about the problem 

46 """ 

47 super().__init__("KEY", message) 

48 

49 

50class Crypt4GHHeaderException(Crypt4GHException): 

51 """An exception related to Crypt4GH header processing problem.""" 

52 

53 def __init__(self, message: str) -> None: 

54 """Initializes the header exception. 

55 

56 Parameters: 

57 message: a descriptive message about the problem 

58 """ 

59 super().__init__("HEADER", message) 

60 

61 

62class Crypt4GHHeaderPacketException(Crypt4GHException): 

63 """An exception related to particular Crypt4GH header packet 

64 processing problem. 

65 

66 """ 

67 

68 def __init__(self, message: str) -> None: 

69 """Initializes the header packet exception. 

70 

71 Parameters: 

72 message: a descriptive message about the problem 

73 """ 

74 super().__init__("HEADERPACKET", message) 

75 

76 

77class Crypt4GHDEKException(Crypt4GHException): 

78 """Base exception raised when something goes wrong with Data 

79 Encryption Key(s). 

80 

81 """ 

82 

83 def __init__(self, message: str) -> None: 

84 """Initializes the DEK exception. 

85 

86 Parameters: 

87 message: a descriptive message about the problem 

88 

89 """ 

90 super().__init__("DEK", message) 

91 

92 

93class Crypt4GHProcessedException(Crypt4GHException): 

94 """An exception for signalling the container cannot be processed 

95 again from the beginning. 

96 

97 """ 

98 

99 def __init__(self, message: str) -> None: 

100 """Initializes the Processed exception. 

101 

102 Parameters: 

103 message: a decriptive message about the problem 

104 

105 """ 

106 super().__init__("PROCESSED", message)