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 70e67bf

Browse filesBrowse files
authored
Merge pull request #2212 from python-gitlab/jlvillal/config
chore: remove broad Exception catching from `config.py`
2 parents 9aecc9e + 0abc90b commit 70e67bf
Copy full SHA for 70e67bf

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
@@ -17,6 +17,8 @@
1717

1818
HELPER_ATTRIBUTES = ["job_token", "http_password", "private_token", "oauth_token"]
1919

20+
_CONFIG_PARSER_ERRORS = (configparser.NoOptionError, configparser.NoSectionError)
21+
2022

2123
def _resolve_file(filepath: Union[Path, str]) -> str:
2224
resolved = Path(filepath).resolve(strict=True)
@@ -148,108 +150,102 @@ def _parse_config(self) -> None:
148150
# Value Error means the option exists but isn't a boolean.
149151
# Get as a string instead as it should then be a local path to a
150152
# CA bundle.
151-
try:
152-
self.ssl_verify = _config.get("global", "ssl_verify")
153-
except Exception: # pragma: no cover
154-
pass
155-
except Exception:
153+
self.ssl_verify = _config.get("global", "ssl_verify")
154+
except _CONFIG_PARSER_ERRORS:
156155
pass
157156
try:
158157
self.ssl_verify = _config.getboolean(self.gitlab_id, "ssl_verify")
159158
except ValueError:
160159
# Value Error means the option exists but isn't a boolean.
161160
# Get as a string instead as it should then be a local path to a
162161
# CA bundle.
163-
try:
164-
self.ssl_verify = _config.get(self.gitlab_id, "ssl_verify")
165-
except Exception: # pragma: no cover
166-
pass
167-
except Exception:
162+
self.ssl_verify = _config.get(self.gitlab_id, "ssl_verify")
163+
except _CONFIG_PARSER_ERRORS:
168164
pass
169165

170166
try:
171167
self.timeout = _config.getint("global", "timeout")
172-
except Exception:
168+
except _CONFIG_PARSER_ERRORS:
173169
pass
174170
try:
175171
self.timeout = _config.getint(self.gitlab_id, "timeout")
176-
except Exception:
172+
except _CONFIG_PARSER_ERRORS:
177173
pass
178174

179175
try:
180176
self.private_token = _config.get(self.gitlab_id, "private_token")
181-
except Exception:
177+
except _CONFIG_PARSER_ERRORS:
182178
pass
183179

184180
try:
185181
self.oauth_token = _config.get(self.gitlab_id, "oauth_token")
186-
except Exception:
182+
except _CONFIG_PARSER_ERRORS:
187183
pass
188184

189185
try:
190186
self.job_token = _config.get(self.gitlab_id, "job_token")
191-
except Exception:
187+
except _CONFIG_PARSER_ERRORS:
192188
pass
193189

194190
try:
195191
self.http_username = _config.get(self.gitlab_id, "http_username")
196192
self.http_password = _config.get(
197193
self.gitlab_id, "http_password"
198194
) # pragma: no cover
199-
except Exception:
195+
except _CONFIG_PARSER_ERRORS:
200196
pass
201197

202198
self._get_values_from_helper()
203199

204200
try:
205201
self.api_version = _config.get("global", "api_version")
206-
except Exception:
202+
except _CONFIG_PARSER_ERRORS:
207203
pass
208204
try:
209205
self.api_version = _config.get(self.gitlab_id, "api_version")
210-
except Exception:
206+
except _CONFIG_PARSER_ERRORS:
211207
pass
212208
if self.api_version not in ("4",):
213209
raise GitlabDataError(f"Unsupported API version: {self.api_version}")
214210

215211
for section in ["global", self.gitlab_id]:
216212
try:
217213
self.per_page = _config.getint(section, "per_page")
218-
except Exception:
214+
except _CONFIG_PARSER_ERRORS:
219215
pass
220216
if self.per_page is not None and not 0 <= self.per_page <= 100:
221217
raise GitlabDataError(f"Unsupported per_page number: {self.per_page}")
222218

223219
try:
224220
self.pagination = _config.get(self.gitlab_id, "pagination")
225-
except Exception:
221+
except _CONFIG_PARSER_ERRORS:
226222
pass
227223

228224
try:
229225
self.order_by = _config.get(self.gitlab_id, "order_by")
230-
except Exception:
226+
except _CONFIG_PARSER_ERRORS:
231227
pass
232228

233229
try:
234230
self.user_agent = _config.get("global", "user_agent")
235-
except Exception:
231+
except _CONFIG_PARSER_ERRORS:
236232
pass
237233
try:
238234
self.user_agent = _config.get(self.gitlab_id, "user_agent")
239-
except Exception:
235+
except _CONFIG_PARSER_ERRORS:
240236
pass
241237

242238
try:
243239
self.retry_transient_errors = _config.getboolean(
244240
"global", "retry_transient_errors"
245241
)
246-
except Exception:
242+
except _CONFIG_PARSER_ERRORS:
247243
pass
248244
try:
249245
self.retry_transient_errors = _config.getboolean(
250246
self.gitlab_id, "retry_transient_errors"
251247
)
252-
except Exception:
248+
except _CONFIG_PARSER_ERRORS:
253249
pass
254250

255251
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.