Update bare exceptions to specify Exception.

This will keep us from accidentally catching program-exiting exceptions
like KeyboardInterupt and SystemExit.
This commit is contained in:
Toshio Kuratomi
2018-09-07 17:59:46 -07:00
parent 5147e792d3
commit 3fba006207
320 changed files with 659 additions and 656 deletions

View File

@@ -78,7 +78,7 @@ def axapi_call(module, url, post=None):
data = {"response": {"status": "OK"}}
else:
data = {"response": {"status": "fail", "err": {"msg": raw_data}}}
except:
except Exception:
module.fail_json(msg="could not read the result from the host")
finally:
rsp.close()
@@ -126,7 +126,7 @@ def axapi_call_v3(module, url, method=None, body=None, signature=None):
data = {"response": {"status": "OK"}}
else:
data = {"response": {"status": "fail", "err": {"msg": raw_data}}}
except:
except Exception:
module.fail_json(msg="could not read the result from the host")
finally:
rsp.close()

View File

@@ -148,7 +148,7 @@ class ACIModule(object):
return true
elif bool_value is False:
return false
except:
except Exception:
# This provides backward compatibility to Ansible v2.4, deprecate in Ansible v2.8
if value == true:
self.module.deprecate("Boolean value '%s' is no longer valid, please use 'yes' as a boolean value." % value, '2.9')
@@ -164,7 +164,7 @@ class ACIModule(object):
''' Return an ACI-compatible ISO8601 formatted time: 2123-12-12T00:00:00.000+00:00 '''
try:
return dt.isoformat(timespec='milliseconds')
except:
except Exception:
tz = dt.strftime('%z')
return '%s.%03d%s:%s' % (dt.strftime('%Y-%m-%dT%H:%M:%S'), dt.microsecond / 1000, tz[:3], tz[3:])
@@ -231,7 +231,7 @@ class ACIModule(object):
try:
sig_key = load_privatekey(FILETYPE_PEM, open(self.params['private_key'], 'r').read())
except:
except Exception:
self.module.fail_json(msg='Cannot load private key %s' % self.params['private_key'])
# NOTE: ACI documentation incorrectly adds a space between method and path

View File

@@ -183,7 +183,7 @@ class MSCModule(object):
elif self.status >= 400:
try:
payload = json.loads(resp.read())
except:
except Exception:
payload = json.loads(info['body'])
if 'code' in payload:
self.fail_json(msg='MSC Error {code}: {message}'.format(**payload), data=data, info=info, payload=payload)

View File

@@ -147,7 +147,7 @@ def content_to_dict(module, content):
if not content_dict:
raise Exception()
except:
except Exception:
module.fail_json(msg="Unable to convert 'content' to a dict, please check if valid")
# replace the string with the dict
@@ -163,7 +163,7 @@ def do_load_resource(module, collection, name):
try:
item = find_collection_item(collection, name, '')
except:
except Exception:
module.fail_json(msg="An error occurred while running 'find_collection_item'")
if item.exists:

View File

@@ -38,7 +38,7 @@ try:
from ansible.module_utils.network.cnos import cnos_errorcodes
from ansible.module_utils.network.cnos import cnos_devicerules
HAS_LIB = True
except:
except Exception:
HAS_LIB = False
from distutils.cmd import Command
from ansible.module_utils._text import to_text
@@ -1372,7 +1372,7 @@ def enterEnableModeForDevice(enablePassword, timeout, obj):
gotit = buff.find("#")
if(gotit != -1):
return retVal
except:
except Exception:
retVal = retVal + "\n Error-101"
flag = True
if(retVal == ""):
@@ -1396,7 +1396,7 @@ def waitForDeviceResponse(command, prompt, timeout, obj):
gotit = buff.find(prompt)
if(gotit != -1):
flag = True
except:
except Exception:
# debugOutput(prompt)
if prompt == "(yes/no)?":
retVal = retVal

View File

@@ -461,7 +461,7 @@ class Template:
if value:
try:
return ast.literal_eval(value)
except:
except Exception:
return str(value)
else:
return None

View File

@@ -79,7 +79,7 @@ def backup(module, running_config):
if not os.path.exists(backup_path):
try:
os.mkdir(backup_path)
except:
except Exception:
module.fail_json(msg="Can't create directory {0} Permission denied ?".format(backup_path))
tstamp = time.strftime("%Y-%m-%d@%H:%M:%S", time.localtime(time.time()))
if 0 < len(backup_filename):
@@ -88,7 +88,7 @@ def backup(module, running_config):
filename = '%s/%s_config.%s' % (backup_path, module.params['host'], tstamp)
try:
open(filename, 'w').write(running_config)
except:
except Exception:
module.fail_json(msg="Can't create backup file {0} Permission denied ?".format(filename))

View File

@@ -292,7 +292,7 @@ class MerakiModule(object):
body=json.loads(to_native(info['body'])))
try:
return json.loads(to_native(resp.read()))
except:
except Exception:
pass
def exit_json(self, **kwargs):