mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 05:42:50 +00:00
Ensure that current uses of BaseException are required
* In some cases, it appears that Exception should have been used instead as there's no need to catch sys.exit KeyboardInterrupt and similar. * In a few cases, it appears that BaseException is used because a library we depend on calls sys.exit() contrary to good coding design. Comment those so that we know that those have been audited and found to be correct and change to use (Exception, SystemExit) instead.
This commit is contained in:
@@ -289,7 +289,7 @@ from ansible.module_utils.ec2 import AWSRetry, boto3_tag_list_to_ansible_dict, c
|
||||
|
||||
try:
|
||||
import botocore
|
||||
except BaseException:
|
||||
except Exception:
|
||||
pass # caught by imported HAS_BOTO3
|
||||
|
||||
|
||||
|
||||
@@ -159,7 +159,7 @@ def main():
|
||||
obj.create()
|
||||
else:
|
||||
obj.modify()
|
||||
except BaseException as e:
|
||||
except Exception as e:
|
||||
module.fail_json(
|
||||
msg='Creating/editing dns entry {} in {} failed: {}'.format(name, container, e)
|
||||
)
|
||||
@@ -170,7 +170,7 @@ def main():
|
||||
if not module.check_mode:
|
||||
obj.remove()
|
||||
changed = True
|
||||
except BaseException as e:
|
||||
except Exception as e:
|
||||
module.fail_json(
|
||||
msg='Removing dns entry {} in {} failed: {}'.format(name, container, e)
|
||||
)
|
||||
|
||||
@@ -513,7 +513,7 @@ def main():
|
||||
obj.create()
|
||||
elif changed:
|
||||
obj.modify()
|
||||
except BaseException as err:
|
||||
except Exception as err:
|
||||
module.fail_json(
|
||||
msg='Creating/editing share {} in {} failed: {}'.format(
|
||||
name,
|
||||
@@ -528,7 +528,7 @@ def main():
|
||||
if not module.check_mode:
|
||||
obj.remove()
|
||||
changed = True
|
||||
except BaseException as err:
|
||||
except Exception as err:
|
||||
module.fail_json(
|
||||
msg='Removing share {} in {} failed: {}'.format(
|
||||
name,
|
||||
|
||||
@@ -152,7 +152,8 @@ def create_maintenance(zbx, group_ids, host_ids, start_time, maintenance_type, p
|
||||
}]
|
||||
}
|
||||
)
|
||||
except BaseException as e:
|
||||
# zabbix_api can call sys.exit() so we need to catch SystemExit here
|
||||
except (Exception, SystemExit) as e:
|
||||
return 1, None, str(e)
|
||||
return 0, None, None
|
||||
|
||||
@@ -176,7 +177,8 @@ def update_maintenance(zbx, maintenance_id, group_ids, host_ids, start_time, mai
|
||||
}]
|
||||
}
|
||||
)
|
||||
except BaseException as e:
|
||||
# zabbix_api can call sys.exit() so we need to catch SystemExit here
|
||||
except (Exception, SystemExit) as e:
|
||||
return 1, None, str(e)
|
||||
return 0, None, None
|
||||
|
||||
@@ -193,7 +195,8 @@ def get_maintenance(zbx, name):
|
||||
"selectHosts": "extend"
|
||||
}
|
||||
)
|
||||
except BaseException as e:
|
||||
# zabbix_api can call sys.exit() so we need to catch SystemExit here
|
||||
except (Exception, SystemExit) as e:
|
||||
return 1, None, str(e)
|
||||
|
||||
for maintenance in maintenances:
|
||||
@@ -207,7 +210,8 @@ def get_maintenance(zbx, name):
|
||||
def delete_maintenance(zbx, maintenance_id):
|
||||
try:
|
||||
zbx.maintenance.delete([maintenance_id])
|
||||
except BaseException as e:
|
||||
# zabbix_api can call sys.exit() so we need to catch SystemExit here
|
||||
except (Exception, SystemExit) as e:
|
||||
return 1, None, str(e)
|
||||
return 0, None, None
|
||||
|
||||
@@ -225,7 +229,8 @@ def get_group_ids(zbx, host_groups):
|
||||
}
|
||||
}
|
||||
)
|
||||
except BaseException as e:
|
||||
# zabbix_api can call sys.exit() so we need to catch SystemExit here
|
||||
except (Exception, SystemExit) as e:
|
||||
return 1, None, str(e)
|
||||
|
||||
if not result:
|
||||
@@ -249,7 +254,8 @@ def get_host_ids(zbx, host_names):
|
||||
}
|
||||
}
|
||||
)
|
||||
except BaseException as e:
|
||||
# zabbix_api can call sys.exit() so we need to catch SystemExit here
|
||||
except (Exception, SystemExit) as e:
|
||||
return 1, None, str(e)
|
||||
|
||||
if not result:
|
||||
@@ -308,7 +314,8 @@ def main():
|
||||
zbx = ZabbixAPI(server_url, timeout=timeout, user=http_login_user, passwd=http_login_password,
|
||||
validate_certs=validate_certs)
|
||||
zbx.login(login_user, login_password)
|
||||
except BaseException as e:
|
||||
# zabbix_api can call sys.exit() so we need to catch SystemExit here
|
||||
except (Exception, SystemExit) as e:
|
||||
module.fail_json(msg="Failed to connect to Zabbix server: %s" % e)
|
||||
|
||||
changed = False
|
||||
|
||||
Reference in New Issue
Block a user