|
34 | 34 |
|
35 | 35 | HELPER_ATTRIBUTES = ["job_token", "http_password", "private_token", "oauth_token"]
|
36 | 36 |
|
| 37 | +_CONFIG_PARSER_ERRORS = (configparser.NoOptionError, configparser.NoSectionError) |
| 38 | + |
37 | 39 |
|
38 | 40 | def _resolve_file(filepath: Union[Path, str]) -> str:
|
39 | 41 | resolved = Path(filepath).resolve(strict=True)
|
@@ -165,108 +167,102 @@ def _parse_config(self) -> None:
|
165 | 167 | # Value Error means the option exists but isn't a boolean.
|
166 | 168 | # Get as a string instead as it should then be a local path to a
|
167 | 169 | # CA bundle.
|
168 |
| - try: |
169 |
| - self.ssl_verify = _config.get("global", "ssl_verify") |
170 |
| - except Exception: # pragma: no cover |
171 |
| - pass |
172 |
| - except Exception: |
| 170 | + self.ssl_verify = _config.get("global", "ssl_verify") |
| 171 | + except _CONFIG_PARSER_ERRORS: |
173 | 172 | pass
|
174 | 173 | try:
|
175 | 174 | self.ssl_verify = _config.getboolean(self.gitlab_id, "ssl_verify")
|
176 | 175 | except ValueError:
|
177 | 176 | # Value Error means the option exists but isn't a boolean.
|
178 | 177 | # Get as a string instead as it should then be a local path to a
|
179 | 178 | # CA bundle.
|
180 |
| - try: |
181 |
| - self.ssl_verify = _config.get(self.gitlab_id, "ssl_verify") |
182 |
| - except Exception: # pragma: no cover |
183 |
| - pass |
184 |
| - except Exception: |
| 179 | + self.ssl_verify = _config.get(self.gitlab_id, "ssl_verify") |
| 180 | + except _CONFIG_PARSER_ERRORS: |
185 | 181 | pass
|
186 | 182 |
|
187 | 183 | try:
|
188 | 184 | self.timeout = _config.getint("global", "timeout")
|
189 |
| - except Exception: |
| 185 | + except _CONFIG_PARSER_ERRORS: |
190 | 186 | pass
|
191 | 187 | try:
|
192 | 188 | self.timeout = _config.getint(self.gitlab_id, "timeout")
|
193 |
| - except Exception: |
| 189 | + except _CONFIG_PARSER_ERRORS: |
194 | 190 | pass
|
195 | 191 |
|
196 | 192 | try:
|
197 | 193 | self.private_token = _config.get(self.gitlab_id, "private_token")
|
198 |
| - except Exception: |
| 194 | + except _CONFIG_PARSER_ERRORS: |
199 | 195 | pass
|
200 | 196 |
|
201 | 197 | try:
|
202 | 198 | self.oauth_token = _config.get(self.gitlab_id, "oauth_token")
|
203 |
| - except Exception: |
| 199 | + except _CONFIG_PARSER_ERRORS: |
204 | 200 | pass
|
205 | 201 |
|
206 | 202 | try:
|
207 | 203 | self.job_token = _config.get(self.gitlab_id, "job_token")
|
208 |
| - except Exception: |
| 204 | + except _CONFIG_PARSER_ERRORS: |
209 | 205 | pass
|
210 | 206 |
|
211 | 207 | try:
|
212 | 208 | self.http_username = _config.get(self.gitlab_id, "http_username")
|
213 | 209 | self.http_password = _config.get(
|
214 | 210 | self.gitlab_id, "http_password"
|
215 | 211 | ) # pragma: no cover
|
216 |
| - except Exception: |
| 212 | + except _CONFIG_PARSER_ERRORS: |
217 | 213 | pass
|
218 | 214 |
|
219 | 215 | self._get_values_from_helper()
|
220 | 216 |
|
221 | 217 | try:
|
222 | 218 | self.api_version = _config.get("global", "api_version")
|
223 |
| - except Exception: |
| 219 | + except _CONFIG_PARSER_ERRORS: |
224 | 220 | pass
|
225 | 221 | try:
|
226 | 222 | self.api_version = _config.get(self.gitlab_id, "api_version")
|
227 |
| - except Exception: |
| 223 | + except _CONFIG_PARSER_ERRORS: |
228 | 224 | pass
|
229 | 225 | if self.api_version not in ("4",):
|
230 | 226 | raise GitlabDataError(f"Unsupported API version: {self.api_version}")
|
231 | 227 |
|
232 | 228 | for section in ["global", self.gitlab_id]:
|
233 | 229 | try:
|
234 | 230 | self.per_page = _config.getint(section, "per_page")
|
235 |
| - except Exception: |
| 231 | + except _CONFIG_PARSER_ERRORS: |
236 | 232 | pass
|
237 | 233 | if self.per_page is not None and not 0 <= self.per_page <= 100:
|
238 | 234 | raise GitlabDataError(f"Unsupported per_page number: {self.per_page}")
|
239 | 235 |
|
240 | 236 | try:
|
241 | 237 | self.pagination = _config.get(self.gitlab_id, "pagination")
|
242 |
| - except Exception: |
| 238 | + except _CONFIG_PARSER_ERRORS: |
243 | 239 | pass
|
244 | 240 |
|
245 | 241 | try:
|
246 | 242 | self.order_by = _config.get(self.gitlab_id, "order_by")
|
247 |
| - except Exception: |
| 243 | + except _CONFIG_PARSER_ERRORS: |
248 | 244 | pass
|
249 | 245 |
|
250 | 246 | try:
|
251 | 247 | self.user_agent = _config.get("global", "user_agent")
|
252 |
| - except Exception: |
| 248 | + except _CONFIG_PARSER_ERRORS: |
253 | 249 | pass
|
254 | 250 | try:
|
255 | 251 | self.user_agent = _config.get(self.gitlab_id, "user_agent")
|
256 |
| - except Exception: |
| 252 | + except _CONFIG_PARSER_ERRORS: |
257 | 253 | pass
|
258 | 254 |
|
259 | 255 | try:
|
260 | 256 | self.retry_transient_errors = _config.getboolean(
|
261 | 257 | "global", "retry_transient_errors"
|
262 | 258 | )
|
263 |
| - except Exception: |
| 259 | + except _CONFIG_PARSER_ERRORS: |
264 | 260 | pass
|
265 | 261 | try:
|
266 | 262 | self.retry_transient_errors = _config.getboolean(
|
267 | 263 | self.gitlab_id, "retry_transient_errors"
|
268 | 264 | )
|
269 |
| - except Exception: |
| 265 | + except _CONFIG_PARSER_ERRORS: |
270 | 266 | pass
|
271 | 267 |
|
272 | 268 | def _get_values_from_helper(self) -> None:
|
|
0 commit comments