From 533e3cba1deb85c96cbfb16c9a2758a78118d241 Mon Sep 17 00:00:00 2001 From: Thanh Ha Date: Tue, 5 Oct 2021 12:17:02 -0400 Subject: [PATCH] Refactor: Resolve flake8 E722 bare except It is considered bad practice to use a bare except as this kind of except statement can have untended consequences such as disabling ctrl+c interrupts. At the vary least we should use Exception however a more specific one would be better. This PR uses the general Exception to resolve the linter which we can add more specific ones later when we can appropriately unit test the code. Signed-off-by: Thanh Ha Change-Id: I9afcff49f34326d279a63ce972d12f9aa72f18e2 --- lftools/api/endpoints/gerrit.py | 2 +- lftools/cli/infofile.py | 2 +- lftools/cli/ldap_cli.py | 2 +- lftools/deploy.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lftools/api/endpoints/gerrit.py b/lftools/api/endpoints/gerrit.py index 4060e1e2..423a5021 100644 --- a/lftools/api/endpoints/gerrit.py +++ b/lftools/api/endpoints/gerrit.py @@ -248,7 +248,7 @@ class Gerrit(client.RestApi): log.info(access_str) try: result = self.get(access_str)[1] - except: + except Exception: log.info("Not found {}".format(access_str)) exit(1) log.info("found {} {}".format(access_str, mylist)) diff --git a/lftools/cli/infofile.py b/lftools/cli/infofile.py index 446d2e5e..d12c27de 100644 --- a/lftools/cli/infofile.py +++ b/lftools/cli/infofile.py @@ -79,7 +79,7 @@ def create_info_file(ctx, gerrit_url, gerrit_project, directory, empty, tsc_appr try: owner = result["local"]["refs/*"]["permissions"]["owner"]["rules"] - except: + except Exception: print("ERROR: Check project config, no owner set!") for x in owner: diff --git a/lftools/cli/ldap_cli.py b/lftools/cli/ldap_cli.py index 1d6d6f44..0088f6ea 100644 --- a/lftools/cli/ldap_cli.py +++ b/lftools/cli/ldap_cli.py @@ -173,7 +173,7 @@ def csv(ctx, ldap_server, ldap_group_base, ldap_user_base, groups): user_info = ldap_query(l, ldap_user_base, user, ["uid", "cn", "mail"]) try: print("%s,%s" % (group_name, user_to_csv(user_info))) - except: + except Exception: eprint("Error parsing user: %s" % user) continue ldap_disconnect(l) diff --git a/lftools/deploy.py b/lftools/deploy.py index c59640b4..6a7d34db 100755 --- a/lftools/deploy.py +++ b/lftools/deploy.py @@ -194,7 +194,7 @@ def _get_node_from_xml(xml_data, tag_name): try: dom1 = parseString(xml_data) childnode = dom1.getElementsByTagName(tag_name)[0] - except: + except Exception: _log_error_and_exit("Received bad XML, can not find tag {}".format(tag_name), xml_data) return childnode.firstChild.data -- 2.16.6