Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b70a438

Browse filesBrowse files
chore: remove broad Exception catching from config.py
Change "except Exception:" catching to more granular exceptions. A step in enabling the "broad-except" check in pylint.
1 parent e2ea8b8 commit b70a438
Copy full SHA for b70a438

File tree

Expand file treeCollapse file tree

1 file changed

+21
-25
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+21
-25
lines changed
Open diff view settings
Collapse file

‎gitlab/config.py‎

Copy file name to clipboardExpand all lines: gitlab/config.py
+21-25Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434

3535
HELPER_ATTRIBUTES = ["job_token", "http_password", "private_token", "oauth_token"]
3636

37+
_CONFIG_PARSER_ERRORS = (configparser.NoOptionError, configparser.NoSectionError)
38+
3739

3840
def _resolve_file(filepath: Union[Path, str]) -> str:
3941
resolved = Path(filepath).resolve(strict=True)
@@ -165,108 +167,102 @@ def _parse_config(self) -> None:
165167
# Value Error means the option exists but isn't a boolean.
166168
# Get as a string instead as it should then be a local path to a
167169
# 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:
173172
pass
174173
try:
175174
self.ssl_verify = _config.getboolean(self.gitlab_id, "ssl_verify")
176175
except ValueError:
177176
# Value Error means the option exists but isn't a boolean.
178177
# Get as a string instead as it should then be a local path to a
179178
# 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:
185181
pass
186182

187183
try:
188184
self.timeout = _config.getint("global", "timeout")
189-
except Exception:
185+
except _CONFIG_PARSER_ERRORS:
190186
pass
191187
try:
192188
self.timeout = _config.getint(self.gitlab_id, "timeout")
193-
except Exception:
189+
except _CONFIG_PARSER_ERRORS:
194190
pass
195191

196192
try:
197193
self.private_token = _config.get(self.gitlab_id, "private_token")
198-
except Exception:
194+
except _CONFIG_PARSER_ERRORS:
199195
pass
200196

201197
try:
202198
self.oauth_token = _config.get(self.gitlab_id, "oauth_token")
203-
except Exception:
199+
except _CONFIG_PARSER_ERRORS:
204200
pass
205201

206202
try:
207203
self.job_token = _config.get(self.gitlab_id, "job_token")
208-
except Exception:
204+
except _CONFIG_PARSER_ERRORS:
209205
pass
210206

211207
try:
212208
self.http_username = _config.get(self.gitlab_id, "http_username")
213209
self.http_password = _config.get(
214210
self.gitlab_id, "http_password"
215211
) # pragma: no cover
216-
except Exception:
212+
except _CONFIG_PARSER_ERRORS:
217213
pass
218214

219215
self._get_values_from_helper()
220216

221217
try:
222218
self.api_version = _config.get("global", "api_version")
223-
except Exception:
219+
except _CONFIG_PARSER_ERRORS:
224220
pass
225221
try:
226222
self.api_version = _config.get(self.gitlab_id, "api_version")
227-
except Exception:
223+
except _CONFIG_PARSER_ERRORS:
228224
pass
229225
if self.api_version not in ("4",):
230226
raise GitlabDataError(f"Unsupported API version: {self.api_version}")
231227

232228
for section in ["global", self.gitlab_id]:
233229
try:
234230
self.per_page = _config.getint(section, "per_page")
235-
except Exception:
231+
except _CONFIG_PARSER_ERRORS:
236232
pass
237233
if self.per_page is not None and not 0 <= self.per_page <= 100:
238234
raise GitlabDataError(f"Unsupported per_page number: {self.per_page}")
239235

240236
try:
241237
self.pagination = _config.get(self.gitlab_id, "pagination")
242-
except Exception:
238+
except _CONFIG_PARSER_ERRORS:
243239
pass
244240

245241
try:
246242
self.order_by = _config.get(self.gitlab_id, "order_by")
247-
except Exception:
243+
except _CONFIG_PARSER_ERRORS:
248244
pass
249245

250246
try:
251247
self.user_agent = _config.get("global", "user_agent")
252-
except Exception:
248+
except _CONFIG_PARSER_ERRORS:
253249
pass
254250
try:
255251
self.user_agent = _config.get(self.gitlab_id, "user_agent")
256-
except Exception:
252+
except _CONFIG_PARSER_ERRORS:
257253
pass
258254

259255
try:
260256
self.retry_transient_errors = _config.getboolean(
261257
"global", "retry_transient_errors"
262258
)
263-
except Exception:
259+
except _CONFIG_PARSER_ERRORS:
264260
pass
265261
try:
266262
self.retry_transient_errors = _config.getboolean(
267263
self.gitlab_id, "retry_transient_errors"
268264
)
269-
except Exception:
265+
except _CONFIG_PARSER_ERRORS:
270266
pass
271267

272268
def _get_values_from_helper(self) -> None:

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.