Coverage for src / mafw / mafw_errors.py: 97%

70 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-03-30 16:10 +0000

1# Copyright 2025–2026 European Union 

2# Author: Bulgheroni Antonio (antonio.bulgheroni@ec.europa.eu) 

3# SPDX-License-Identifier: EUPL-1.2 

4""" 

5Module defines MAFw exceptions 

6""" 

7 

8 

9class MAFwException(Exception): 

10 """Base class for MAFwException""" 

11 

12 pass 

13 

14 

15class ProcessorParameterError(MAFwException): 

16 """Error with a processor parameter""" 

17 

18 pass 

19 

20 

21class InvalidConfigurationError(MAFwException): 

22 """Error with the configuration of a processor""" 

23 

24 pass 

25 

26 

27class MissingOverloadedMethod(UserWarning): 

28 """ 

29 Warning issued when the user did not overload a required method. 

30 

31 It is a warning and not an error because the execution framework might still work, but the results might be 

32 different from what is expected. 

33 """ 

34 

35 pass 

36 

37 

38class MissingSuperCall(UserWarning): 

39 """ 

40 Warning issued when the user did not invoke the super method for some specific processor methods. 

41 

42 Those methods (like :meth:`~mafw.processor.Processor.start` and :meth:`~mafw.processor.Processor.finish`) have not 

43 empty implementation also in the base class, meaning that if the user forgets to call *super* in their overloads, 

44 then the basic implementation will be gone. 

45 

46 It is a warning and not an error because the execution framework might sill work, but the results might be 

47 different from what is expected. 

48 """ 

49 

50 pass 

51 

52 

53class AbortProcessorException(MAFwException): 

54 """Exception raised during the execution of a processor requiring immediate exit.""" 

55 

56 pass 

57 

58 

59class RunnerNotInitialized(MAFwException): 

60 """Exception raised when attempting to run a not initialized Runner.""" 

61 

62 pass 

63 

64 

65class InvalidSteeringFile(MAFwException): 

66 """Exception raised when validating an invalid steering file""" 

67 

68 pass 

69 

70 

71class ValidationIssue(InvalidSteeringFile): 

72 """Base class for steering validation issues.""" 

73 

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

75 super().__init__(message) 

76 

77 

78class MissingProcessorsToRunIssue(ValidationIssue): 

79 """Issue raised when the steering file does not declare ``processors_to_run``.""" 

80 

81 def __init__(self) -> None: 

82 super().__init__('Missing processors_to_run') 

83 

84 

85class ProcessorsToRunNotListIssue(ValidationIssue): 

86 """Issue raised when ``processors_to_run`` is not a list.""" 

87 

88 def __init__(self) -> None: 

89 super().__init__('processors_to_run must be a list') 

90 

91 

92class MissingUserInterfaceSectionIssue(ValidationIssue): 

93 """Issue raised when the ``UserInterface`` section is missing.""" 

94 

95 def __init__(self) -> None: 

96 super().__init__('Missing UserInterface section') 

97 

98 

99class UnknownProcessorsToRunEntryIssue(ValidationIssue): 

100 """Issue raised when a processor reference in ``processors_to_run`` cannot be resolved.""" 

101 

102 def __init__(self, entry: str) -> None: 

103 super().__init__(f'Processor reference {entry} not defined') 

104 

105 

106class UnknownGroupMemberIssue(ValidationIssue): 

107 """Issue raised when a group references an unknown processor or nested group.""" 

108 

109 def __init__(self, group: str, member: str) -> None: 

110 super().__init__(f"Group '{group}' references unknown processor or group '{member}'") 

111 

112 

113class DuplicateReplicaIssue(ValidationIssue): 

114 """Issue raised when a processor declares duplicate replica identifiers.""" 

115 

116 def __init__(self, base: str, replica: str) -> None: 

117 super().__init__(f"Duplicate replica identifier '{replica}' for processor '{base}'") 

118 

119 

120class CyclicGroupIssue(ValidationIssue): 

121 """Issue raised when cyclic dependencies exist within processor groups.""" 

122 

123 def __init__(self, node: str) -> None: 

124 super().__init__(f"Cyclic group dependency detected at '{node}'") 

125 

126 

127class InvalidFilterConditionIssue(ValidationIssue): 

128 """Issue raised when a filter condition is incomplete or invalid.""" 

129 

130 def __init__( 

131 self, 

132 processor: str, 

133 model: str, 

134 condition: str, 

135 *, 

136 field_name: str | None = None, 

137 reason: str | None = None, 

138 ) -> None: 

139 descriptor = f"Condition '{condition}' for model '{model}' in processor '{processor}'" 

140 if field_name: 

141 descriptor += f" field '{field_name}'" 

142 descriptor += ' is invalid' 

143 if reason: 143 ↛ 145line 143 didn't jump to line 145 because the condition on line 143 was always true

144 descriptor += f': {reason}' 

145 super().__init__(descriptor) 

146 

147 

148class InvalidFilterLogicIssue(ValidationIssue): 

149 """Issue raised when a filter logic expression is invalid.""" 

150 

151 def __init__(self, processor: str, target: str, *, detail: str | None = None) -> None: 

152 descriptor = f"Logic expression for {target} on processor '{processor}' is invalid" 

153 if detail: 153 ↛ 155line 153 didn't jump to line 155 because the condition on line 153 was always true

154 descriptor += f': {detail}' 

155 super().__init__(descriptor) 

156 

157 

158class UnknownProcessor(MAFwException): 

159 """Exception raised when an attempt is made to create an unknown processor""" 

160 

161 pass 

162 

163 

164class UnknownProcessorGroup(MAFwException): 

165 """Exception raised when an attempt is made to create an unknown processor group""" 

166 

167 pass 

168 

169 

170class UnknownDBEngine(MAFwException): 

171 """Exception raised when the user provided an unknown db engine""" 

172 

173 pass 

174 

175 

176class MissingDatabase(MAFwException): 

177 """Exception raised when a processor requiring a database connection is being operated without a database""" 

178 

179 

180class MissingAttribute(MAFwException): 

181 """Exception raised when an attempt is made to execute a statement without a required parameter/attributes""" 

182 

183 

184class ParserConfigurationError(MAFwException): 

185 """Exception raised when an error occurred during the configuration of a filename parser""" 

186 

187 

188class ParsingError(MAFwException): 

189 """Exception raised when a regular expression parsing failed""" 

190 

191 

192class MissingSQLStatement(MAFwException): 

193 """Exception raised when a Trigger is created without any SQL statements.""" 

194 

195 

196class UnsupportedDatabaseError(Exception): 

197 """Error raised when a feature is not supported by the database.""" 

198 

199 

200class ModelError(MAFwException): 

201 """Exception raised when an error in a DB Model class occurs""" 

202 

203 

204class MissingOptionalDependency(UserWarning): 

205 """UserWarning raised when an optional dependency is required""" 

206 

207 

208class PlotterMixinNotInitialized(MAFwException): 

209 """Exception raised when a plotter mixin has not properly initialized"""