Skip to content

Commit

Permalink
SONAR: Specify an exception class to catch or reraise the exception
Browse files Browse the repository at this point in the history
Signed-off-by: Julien Fortin <[email protected]>
  • Loading branch information
julienfortin committed May 4, 2023
1 parent 9796acc commit 7c8627f
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import os, webbrowser, sys

try:
from urllib import pathname2url
except:
except Exception:
from urllib.request import pathname2url

webbrowser.open("file://" + pathname2url(os.path.abspath(sys.argv[1])))
Expand Down
6 changes: 3 additions & 3 deletions ifupdown2/addons/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,9 @@ def __init__(self, *args, **kargs):
)
try:
self.l3_intf_arp_accept = int(l3_intf_arp_accept_str)
except:
except ValueError:
self.l3_intf_arp_accept = int(strtobool(l3_intf_arp_accept_str))
except:
except Exception:
self.l3_intf_arp_accept = 0

self.l3_intf_default_gateway_set_onlink = utils.get_boolean_from_string(
Expand Down Expand Up @@ -469,7 +469,7 @@ def _process_bridge(self, ifaceobj, up, hwaddress, old_mac_addr=None):
try:
if utils.mac_str_to_int(old_mac_addr) != utils.mac_str_to_int(hwaddress):
self.iproute2.bridge_fdb_del(bridgename, old_mac_addr, vlan)
except:
except Exception:
pass
if up:
# check statemanager to delete the old entry if necessary
Expand Down
4 changes: 2 additions & 2 deletions ifupdown2/addons/bond.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ def _add_slaves(self, ifaceobj, runningslaves, ifaceobj_getfunc=None):
for s in removed_slave:
try:
runningslaves.remove(s)
except:
except Exception:
pass

return runningslaves
Expand Down Expand Up @@ -960,7 +960,7 @@ def _query_check(self, ifaceobj, ifaceobjcurr, ifaceobj_getfunc=None):
try:
iface_attrs.remove("es-sys-mac")
self.logger.info("%s: non-root user can't check attribute \"es-sys-mac\" value" % ifaceobj.name)
except:
except Exception:
pass

for attr in iface_attrs:
Expand Down
10 changes: 5 additions & 5 deletions ifupdown2/addons/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@ def __init__(self, *args, **kargs):
module_name=self.__class__.__name__,
attr="bridge_vni_per_svi_limit"
))
except:
except Exception:
self.bridge_vni_per_svi_limit = -1

@staticmethod
Expand Down Expand Up @@ -947,7 +947,7 @@ def __get_vxlan_bridge_name(self, ifaceobj, ifaceobj_getfunc):
for obj in ifaceobj_getfunc(intf):
if obj.link_kind & ifaceLinkKind.BRIDGE:
return obj.name
except:
except Exception:
pass
return None

Expand Down Expand Up @@ -2609,7 +2609,7 @@ def apply_bridge_port_vlan_vni_map(self, ifaceobj):
for vlan_vni_map_entry in bridge_vlan_vni_map_entry.split():
try:
vlans_str, vni_str = utils.get_vlan_vni_in_map_entry(vlan_vni_map_entry)
except:
except Exception:
return self.__warn_bridge_vlan_vni_map_syntax_error(vxlan_name, vlan_vni_map_entry)

# we need to convert vlan_str and vni_str back to a map {vlan: vni}
Expand Down Expand Up @@ -3874,7 +3874,7 @@ def _query_check_bridge_port(self, ifaceobj, ifaceobjcurr,
for vlan_vni in bridge_vlan_vni_map_entry.split():
try:
vlans_str, vni_str = utils.get_vlan_vni_in_map_entry(vlan_vni)
except:
except Exception:
fail = True
self.__warn_bridge_vlan_vni_map_syntax_error(ifname, vlan_vni)
continue
Expand All @@ -3893,7 +3893,7 @@ def _query_check_bridge_port(self, ifaceobj, ifaceobjcurr,

if vlan != cached_vnis[index] or vnis_list[i] != cached_vlans[index]:
fail = True
except:
except Exception:
fail = True

ifaceobjcurr.update_config_with_status("bridge-vlan-vni-map", bridge_vlan_vni_map_entry, fail)
Expand Down
2 changes: 1 addition & 1 deletion ifupdown2/addons/vlan.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def _is_vlan_device(self, ifaceobj):
try:
if self._get_vlan_id(ifaceobj) != -1:
return True
except:
except Exception:
pass
return False

Expand Down
4 changes: 2 additions & 2 deletions ifupdown2/addons/vxlan.py
Original file line number Diff line number Diff line change
Expand Up @@ -1320,14 +1320,14 @@ def vxlan_remote_ip_map(self, ifaceobj, vxlan_mcast_grp_map):
for vni, ip in (vxlan_mcast_grp_map or {}).items():
try:
old_vxlan_remote_ip_map[vni].remove(ip)
except:
except Exception:
pass

for vni, ips in old_vxlan_remote_ip_map.items():
for ip in ips:
try:
self.iproute2.bridge_fdb_del_raw(ifaceobj.name, "00:00:00:00:00:00 dst %s src_vni %s" % (ip, vni))
except:
except Exception:
pass

@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion ifupdown2/lib/gvgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ def propertyGet(self, node_or_link, key):
try:
props = node_or_link['properties']
return props[key]
except:
except Exception:
return None

def propertyRemove(self, node_or_link, key):
Expand Down
4 changes: 2 additions & 2 deletions ifupdown2/lib/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

try:
from ifupdown2.ifupdown.utils import utils
except:
except ImportError:
from ifupdown.utils import utils


Expand Down Expand Up @@ -204,7 +204,7 @@ def __init_debug_logging(self):
try:
directory_to_remove = "%s/%s%s_%s" % (self.LOGGING_DIRECTORY, self.LOGGING_DIRECTORY_PREFIX, ifupdown2_log_dirs[index][0], ifupdown2_log_dirs[index][1])
shutil.rmtree(directory_to_remove, ignore_errors=True)
except:
except Exception:
pass

@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion ifupdown2/nlmanager/ipnetwork.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,5 +185,5 @@ def __str__(self):
def ip_address(ip):
try:
return IPv4Address(ip)
except:
except Exception:
return IPv6Address(ip)
8 changes: 4 additions & 4 deletions ifupdown2/sbin/ifaddon
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def man_rst_body():

print (''' ifupdown2 addon modules add incremental functionality to
core ifupdown2 tool.
All installed addon modules are executed on every interface
listed in the interfaces file. Addon modules are installed under
/usr/share/ifupdownaddons. To see the list of active addon
Expand Down Expand Up @@ -85,13 +85,13 @@ def get_addon_modinfo(modules_dir):
try:
m = __import__(mname)
mclass = getattr(m, mname)
except:
except Exception:
pass
continue
minstance = mclass()
if hasattr(minstance, 'get_modinfo'):
modinfo[mname] = minstance.get_modinfo()
except:
except Exception:
raise

return modinfo
Expand Down Expand Up @@ -233,7 +233,7 @@ def process_move_cmd(args):
pos = int(args.position)
if pos < 0 or pos > len(addon_config.get(op)):
raise Exception('invalid value for position')
except:
except Exception:
raise

if addon_config[op].index(module) == pos:
Expand Down

0 comments on commit 7c8627f

Please sign in to comment.