Skip to content

Commit de781d8

Browse files
committed
Fix redundant exception
1 parent 6841d03 commit de781d8

22 files changed

+54
-54
lines changed

cli/findings_export.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ def __get_component_findings(queue: Queue[tuple[object, ConfigSettings]], write_
294294
findings_list = findings.export_findings(
295295
component.endpoint, component.key, branch=params.get("branch", None), pull_request=params.get("pullRequest", None)
296296
)
297-
except (HTTPError, ConnectionError, RequestException) as e:
297+
except (ConnectionError, RequestException) as e:
298298
log.critical("%s while exporting findings of %s, skipped", util.error_msg(e), str(component))
299299
findings_list = {}
300300
write_queue.put([findings_list, False])
@@ -323,7 +323,7 @@ def __get_component_findings(queue: Queue[tuple[object, ConfigSettings]], write_
323323
if (i_statuses or not status_list) and (i_resols or not resol_list) and (i_types or not type_list) and (i_sevs or not sev_list):
324324
try:
325325
findings_list = component.get_issues(filters=new_params)
326-
except (HTTPError, ConnectionError, RequestException) as e:
326+
except (ConnectionError, RequestException) as e:
327327
log.critical("%s while exporting issues of %s, skipped", util.error_msg(e), str(component))
328328
findings_list = {}
329329
else:
@@ -333,7 +333,7 @@ def __get_component_findings(queue: Queue[tuple[object, ConfigSettings]], write_
333333
if (h_statuses or not status_list) and (h_resols or not resol_list) and (h_types or not type_list) and (h_sevs or not sev_list):
334334
try:
335335
findings_list.update(component.get_hotspots(filters=new_params))
336-
except (HTTPError, ConnectionError, RequestException) as e:
336+
except (ConnectionError, RequestException) as e:
337337
log.error("%s while exporting hotspots of object key %s, skipped", util.error_msg(e), str(component))
338338
else:
339339
log.debug("Status = %s, Types = %s, Resol = %s, Sev = %s", str(h_statuses), str(h_types), str(h_resols), str(h_sevs))
@@ -351,7 +351,7 @@ def store_findings(components_list: dict[str, object], params: ConfigSettings) -
351351
try:
352352
log.debug("Queue %s task %s put", str(my_queue), str(comp))
353353
my_queue.put((comp, params.copy()))
354-
except (HTTPError, ConnectionError, RequestException) as e:
354+
except (ConnectionError, RequestException) as e:
355355
log.critical("%s while exporting findings of %s, skipped", util.error_msg(e), str(comp))
356356

357357
threads = params.get(options.NBR_THREADS, 4)

cli/loc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def __get_csv_row(o: object, **kwargs) -> tuple[list[str], str]:
5151
"""Returns CSV row of object"""
5252
try:
5353
loc = o.loc()
54-
except (HTTPError, ConnectionError, RequestException) as e:
54+
except (ConnectionError, RequestException) as e:
5555
log.warning("%s, LoC export of %s skipped", util.error_msg(e), str(o))
5656
loc = ""
5757
arr = [o.key, loc]
@@ -113,7 +113,7 @@ def __get_object_json_data(o: object, **kwargs) -> dict[str, str]:
113113
d = {parent_type: o.concerned_object.key, "branch": o.name, "ncloc": ""}
114114
try:
115115
d["ncloc"] = o.loc()
116-
except (HTTPError, ConnectionError, RequestException) as e:
116+
except (ConnectionError, RequestException) as e:
117117
log.warning("%s, LoC export of %s skipped", util.error_msg(e), str(o))
118118
if kwargs[options.WITH_NAME]:
119119
d[f"{parent_type}Name"] = o.name

cli/measures_export.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ def __get_measures(obj: object, wanted_metrics: types.KeyList, hist: bool) -> Un
282282
data.update(__get_json_measures_history(obj, wanted_metrics))
283283
else:
284284
data.update(__get_object_measures(obj, wanted_metrics))
285-
except (HTTPError, ConnectionError, RequestException) as e:
285+
except (ConnectionError, RequestException) as e:
286286
log.error("%s, measures export skipped for %s", util.error_msg(e), str(obj))
287287
return None
288288
return data

sonar/app_branches.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def create(cls, app: App, name: str, project_branches: list[Branch]) -> Applicat
109109
params["projectBranch"].append(br_name)
110110
try:
111111
app.endpoint.post(APIS["create"], params=params)
112-
except (HTTPError, ConnectionError, RequestException) as e:
112+
except (ConnectionError, RequestException) as e:
113113
if e.response.status_code == HTTPStatus.BAD_REQUEST:
114114
raise exceptions.ObjectAlreadyExists(f"app.App {app.key} branch '{name}", e.response.text)
115115
log.critical("%s while creating branch '%s' of '%s'", utilities.error_msg(e), name, str(app))
@@ -184,7 +184,7 @@ def update(self, name: str, project_branches: list[Branch]) -> bool:
184184
params["projectBranch"].append(br_name)
185185
try:
186186
ok = self.endpoint.post(APIS["update"], params=params).ok
187-
except (HTTPError, ConnectionError, RequestException) as e:
187+
except (ConnectionError, RequestException) as e:
188188
if e.response.status_code == HTTPStatus.NOT_FOUND:
189189
raise exceptions.ObjectNotFound(str(self), e.response.text)
190190
log.error("%s while updating '%s'", utilities.error_msg(e), str(self))

sonar/applications.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def get_object(cls, endpoint: pf.Platform, key: str) -> Application:
9090
return _OBJECTS[uu]
9191
try:
9292
data = json.loads(endpoint.get(APIS["get"], params={"application": key}).text)["application"]
93-
except (HTTPError, ConnectionError, RequestException) as e:
93+
except (ConnectionError, RequestException) as e:
9494
if e.response.status_code == HTTPStatus.NOT_FOUND:
9595
raise exceptions.ObjectNotFound(key, f"Application key '{key}' not found")
9696
log.error("%s while getting app key '%s'", util.error_msg(e), key)
@@ -133,7 +133,7 @@ def create(cls, endpoint: pf.Platform, key: str, name: str) -> Application:
133133
check_supported(endpoint)
134134
try:
135135
endpoint.post(APIS["create"], params={"key": key, "name": name})
136-
except (HTTPError, ConnectionError, RequestException) as e:
136+
except (ConnectionError, RequestException) as e:
137137
if e.response.status_code == HTTPStatus.BAD_REQUEST:
138138
raise exceptions.ObjectAlreadyExists(key, e.response.text)
139139
log.critical("%s while creating app key '%s'", util.error_msg(e), key)
@@ -150,7 +150,7 @@ def refresh(self) -> None:
150150
try:
151151
self.reload(json.loads(self.get("navigation/component", params={"component": self.key}).text))
152152
self.reload(json.loads(self.get(APIS["get"], params=self.search_params()).text)["application"])
153-
except (HTTPError, ConnectionError, RequestException) as e:
153+
except (ConnectionError, RequestException) as e:
154154
if e.response.status_code == HTTPStatus.NOT_FOUND:
155155
_OBJECTS.pop(self.uuid(), None)
156156
raise exceptions.ObjectNotFound(self.key, f"{str(self)} not found")
@@ -388,7 +388,7 @@ def add_projects(self, project_list: list[str]) -> bool:
388388
try:
389389
r = self.post("applications/add_project", params={"application": self.key, "project": proj})
390390
ok = ok and r.ok
391-
except (HTTPError, ConnectionError, RequestException) as e:
391+
except (ConnectionError, RequestException) as e:
392392
if e.response.status_code == HTTPStatus.NOT_FOUND:
393393
log.warning("Project '%s' not found, can't be added to %s", proj, self)
394394
ok = False

sonar/branches.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def get_object(cls, concerned_object: projects.Project, branch_name: str) -> Bra
8989
return _OBJECTS[uu]
9090
try:
9191
data = json.loads(concerned_object.endpoint.get(APIS["list"], params={"project": concerned_object.key}).text)
92-
except (HTTPError, ConnectionError, RequestException) as e:
92+
except (ConnectionError, RequestException) as e:
9393
if isinstance(HTTPError, e) and e.response.status_code == HTTPStatus.NOT_FOUND:
9494
raise exceptions.ObjectNotFound(concerned_object.key, f"Project '{concerned_object.key}' not found")
9595
log.critical("%s while getting branch '%s' of %s", util.error_msg(e), branch_name, str(concerned_object))
@@ -129,7 +129,7 @@ def refresh(self) -> Branch:
129129
"""
130130
try:
131131
data = json.loads(self.get(APIS["list"], params={"project": self.concerned_object.key}).text)
132-
except (HTTPError, ConnectionError, RequestException) as e:
132+
except (ConnectionError, RequestException) as e:
133133
if isinstance(HTTPError, e) and e.response.status_code == HTTPStatus.NOT_FOUND:
134134
raise exceptions.ObjectNotFound(self.key, f"{str(self)} not found in SonarQube")
135135
log.error("%s while refreshing %s", util.error_msg(e), str(self))
@@ -185,7 +185,7 @@ def delete(self) -> bool:
185185
"""
186186
try:
187187
return sq.delete_object(self, APIS["delete"], {"branch": self.name, "project": self.concerned_object.key}, _OBJECTS)
188-
except (HTTPError, ConnectionError, RequestException) as e:
188+
except (ConnectionError, RequestException) as e:
189189
if isinstance(e, HTTPError) and e.response.status_code == HTTPStatus.BAD_REQUEST:
190190
log.warning("Can't delete %s, it's the main branch", str(self))
191191
else:
@@ -202,7 +202,7 @@ def new_code(self) -> str:
202202
elif self._new_code is None:
203203
try:
204204
data = json.loads(self.get(api=APIS["get_new_code"], params={"project": self.concerned_object.key}).text)
205-
except (HTTPError, ConnectionError, RequestException) as e:
205+
except (ConnectionError, RequestException) as e:
206206
if isinstance(e, HTTPError) and e.response.status_code == HTTPStatus.NOT_FOUND:
207207
raise exceptions.ObjectNotFound(self.concerned_object.key, f"{str(self.concerned_object)} not found")
208208
log.error("%s while getting new code period of %s", util.error_msg(e), str(self))
@@ -265,7 +265,7 @@ def rename(self, new_name):
265265
log.info("Renaming main branch of %s from '%s' to '%s'", str(self.concerned_object), self.name, new_name)
266266
try:
267267
self.post(APIS["rename"], params={"project": self.concerned_object.key, "name": new_name})
268-
except (HTTPError, ConnectionError, RequestException) as e:
268+
except (ConnectionError, RequestException) as e:
269269
if isinstance(HTTPError, e) and e.response.status_code == HTTPStatus.NOT_FOUND:
270270
raise exceptions.ObjectNotFound(self.concerned_object.key, f"str{self.concerned_object} not found")
271271
log.error("%s while renaming %s", util.error_msg(e), str(self))

sonar/devops.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def create(cls, endpoint: platform.Platform, key: str, plt_type: str, url_or_wor
109109
elif plt_type == "bitbucketcloud":
110110
params.update({"clientSecret": _TO_BE_SET, "clientId": _TO_BE_SET, "workspace": url_or_workspace})
111111
endpoint.post(_CREATE_API_BBCLOUD, params=params)
112-
except (HTTPError, ConnectionError, RequestException) as e:
112+
except (ConnectionError, RequestException) as e:
113113
if e.response.status_code == HTTPStatus.BAD_REQUEST and endpoint.edition() in ("community", "developer"):
114114
log.warning("Can't set DevOps platform '%s', don't you have more that 1 of that type?", key)
115115
raise exceptions.UnsupportedOperation(f"Can't set DevOps platform '{key}', don't you have more that 1 of that type?")

sonar/hotspots.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ def search(endpoint: pf.Platform, filters: types.ApiParams = None) -> dict[str,
402402
try:
403403
data = json.loads(endpoint.get(Hotspot.SEARCH_API, params=inline_filters, mute=(HTTPStatus.NOT_FOUND,)).text)
404404
nbr_hotspots = util.nbr_total_elements(data)
405-
except (HTTPError, ConnectionError, RequestException) as e:
405+
except (ConnectionError, RequestException) as e:
406406
if e.response.status_code == HTTPStatus.NOT_FOUND:
407407
log.warning("No hotspots found with search params %s", str(inline_filters))
408408
nbr_hotspots = 0

sonar/measures.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def get(concerned_object: object, metrics_list: KeyList, **kwargs) -> dict[str,
124124

125125
try:
126126
data = json.loads(concerned_object.endpoint.get(Measure.API_READ, params={**kwargs, **params}).text)
127-
except (HTTPError, ConnectionError, RequestException) as e:
127+
except (ConnectionError, RequestException) as e:
128128
if isinstance(e, HTTPError) and e.response.status_code == HTTPStatus.NOT_FOUND:
129129
raise exceptions.ObjectNotFound(concerned_object.key, f"{str(concerned_object)} not found")
130130
log.error("%s while getting measures %s of %s", util.error_msg(e), str(metrics_list), str(concerned_object))
@@ -155,7 +155,7 @@ def get_history(concerned_object: object, metrics_list: KeyList, **kwargs) -> li
155155

156156
try:
157157
data = json.loads(concerned_object.endpoint.get(Measure.API_HISTORY, params={**kwargs, **params}).text)
158-
except (HTTPError, ConnectionError, RequestException) as e:
158+
except (ConnectionError, RequestException) as e:
159159
if isinstance(e, HTTPError) and e.response.status_code == HTTPStatus.NOT_FOUND:
160160
raise exceptions.ObjectNotFound(concerned_object.key, f"{str(concerned_object)} not found")
161161
log.error("%s while getting measures %s history of %s", util.error_msg(e), str(metrics_list), str(concerned_object))

sonar/organizations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def get_object(cls, endpoint: pf.Platform, key: str) -> Organization:
7878
return _OBJECTS[uu]
7979
try:
8080
data = json.loads(endpoint.get(Organization.SEARCH_API, params={"organizations": key}).text)
81-
except (HTTPError, ConnectionError, RequestException) as e:
81+
except (ConnectionError, RequestException) as e:
8282
if isinstance(e, HTTPError) and e.response.status_code == HTTPStatus.NOT_FOUND:
8383
raise exceptions.ObjectNotFound(key, f"Organization '{key}' not found")
8484
log.error("%s getting organization %s", util.error_msg(e), key)

0 commit comments

Comments
 (0)