Refactor: Resolve flake8 E722 bare except 36/68936/2
authorThanh Ha <zxiiro@gmail.com>
Tue, 5 Oct 2021 16:17:02 +0000 (12:17 -0400)
committerThanh Ha <zxiiro@gmail.com>
Tue, 5 Oct 2021 19:19:23 +0000 (15:19 -0400)
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 <zxiiro@gmail.com>
Change-Id: I9afcff49f34326d279a63ce972d12f9aa72f18e2

lftools/api/endpoints/gerrit.py
lftools/cli/infofile.py
lftools/cli/ldap_cli.py
lftools/deploy.py

index 4060e1e..423a502 100644 (file)
@@ -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))
index 446d2e5..d12c27d 100644 (file)
@@ -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:
index 1d6d6f4..0088f6e 100644 (file)
@@ -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)
index c59640b..6a7d34d 100755 (executable)
@@ -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