From 1d30856e67148edf6930041fa4d3b1dec14a78c5 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Sat, 11 Oct 2025 14:27:10 +0200 Subject: [PATCH] Address broad-exception-caught. --- .pylintrc | 1 - plugins/module_utils/_api/auth.py | 2 +- plugins/module_utils/_api/context/config.py | 6 ++--- plugins/module_utils/_common.py | 18 +++++++-------- plugins/module_utils/_common_api.py | 18 +++++++-------- plugins/module_utils/_common_cli.py | 4 ++-- plugins/module_utils/_compose_v2.py | 8 +++---- .../module_utils/_module_container/base.py | 6 ++--- .../_module_container/docker_api.py | 2 +- .../module_utils/_module_container/module.py | 22 +++++++++---------- plugins/module_utils/_socket_handler.py | 2 +- plugins/module_utils/_swarm.py | 6 ++--- plugins/modules/docker_config.py | 2 +- plugins/modules/docker_container_copy_into.py | 4 +--- plugins/modules/docker_image.py | 12 +++++----- plugins/modules/docker_image_export.py | 6 ++--- plugins/modules/docker_image_info.py | 2 +- plugins/modules/docker_image_load.py | 2 +- plugins/modules/docker_image_push.py | 2 +- plugins/modules/docker_image_remove.py | 2 +- plugins/modules/docker_image_tag.py | 2 +- plugins/modules/docker_login.py | 4 ++-- plugins/modules/docker_secret.py | 2 +- plugins/modules/docker_swarm_service.py | 4 ++-- plugins/modules/docker_volume_info.py | 2 +- 25 files changed, 69 insertions(+), 72 deletions(-) diff --git a/.pylintrc b/.pylintrc index ac822cb9..d5099ca1 100644 --- a/.pylintrc +++ b/.pylintrc @@ -381,7 +381,6 @@ disable=raw-checker-failed, # To clean up: abstract-method, arguments-differ, - broad-exception-caught, consider-iterating-dictionary, consider-using-dict-comprehension, consider-using-f-string, diff --git a/plugins/module_utils/_api/auth.py b/plugins/module_utils/_api/auth.py index 3f7958e6..e6d44085 100644 --- a/plugins/module_utils/_api/auth.py +++ b/plugins/module_utils/_api/auth.py @@ -368,7 +368,7 @@ def _load_legacy_config(config_file): } } } - except Exception as e: + except Exception as e: # pylint: disable=broad-exception-caught log.debug(e) pass diff --git a/plugins/module_utils/_api/context/config.py b/plugins/module_utils/_api/context/config.py index 4c5b2608..b3ff0aa0 100644 --- a/plugins/module_utils/_api/context/config.py +++ b/plugins/module_utils/_api/context/config.py @@ -36,7 +36,7 @@ def get_current_context_name_with_source(): json.load(f).get("currentContext", "default"), f"configuration file {docker_cfg_path}", ) - except Exception: + except Exception: # pylint: disable=broad-exception-caught pass return "default", "fallback value" @@ -54,7 +54,7 @@ def write_context_name_to_docker_config(name=None): try: with open(docker_cfg_path, "rt", encoding="utf-8") as f: config = json.load(f) - except Exception as e: + except Exception as e: # pylint: disable=broad-exception-caught return e current_context = config.get("currentContext", None) if current_context and not name: @@ -68,7 +68,7 @@ def write_context_name_to_docker_config(name=None): try: with open(docker_cfg_path, "wt", encoding="utf-8") as f: json.dump(config, f, indent=4) - except Exception as e: + except Exception as e: # pylint: disable=broad-exception-caught return e diff --git a/plugins/module_utils/_common.py b/plugins/module_utils/_common.py index b0bbdd1d..67da04fc 100644 --- a/plugins/module_utils/_common.py +++ b/plugins/module_utils/_common.py @@ -237,7 +237,7 @@ class AnsibleDockerClientBase(Client): self.docker_api_version_str = self.api_version except APIError as exc: self.fail(f"Docker API error: {exc}") - except Exception as exc: + except Exception as exc: # pylint: disable=broad-exception-caught self.fail(f"Error connecting: {exc}") self.docker_api_version = LooseVersion(self.docker_api_version_str) @@ -409,7 +409,7 @@ class AnsibleDockerClientBase(Client): return result except NotFound: return None - except Exception as exc: + except Exception as exc: # pylint: disable=broad-exception-caught self.fail(f"Error inspecting container: {exc}") def get_container(self, name=None): @@ -441,7 +441,7 @@ class AnsibleDockerClientBase(Client): break except SSLError as exc: self._handle_ssl_error(exc) - except Exception as exc: + except Exception as exc: # pylint: disable=broad-exception-caught self.fail(f"Error retrieving container list: {exc}") if result is None: @@ -470,7 +470,7 @@ class AnsibleDockerClientBase(Client): break except SSLError as exc: self._handle_ssl_error(exc) - except Exception as exc: + except Exception as exc: # pylint: disable=broad-exception-caught self.fail(f"Error retrieving network list: {exc}") if result is not None: @@ -483,7 +483,7 @@ class AnsibleDockerClientBase(Client): self.log("Completed network inspection") except NotFound: return None - except Exception as exc: + except Exception as exc: # pylint: disable=broad-exception-caught self.fail(f"Error inspecting network: {exc}") return result @@ -533,7 +533,7 @@ class AnsibleDockerClientBase(Client): except NotFound: self.log(f"Image {name}:{tag} not found.") return None - except Exception as exc: + except Exception as exc: # pylint: disable=broad-exception-caught self.fail(f"Error inspecting image {name}:{tag} - {exc}") return inspection @@ -555,7 +555,7 @@ class AnsibleDockerClientBase(Client): self.fail(f"Error inspecting image ID {image_id} - {exc}") self.log(f"Image {image_id} not found.") return None - except Exception as exc: + except Exception as exc: # pylint: disable=broad-exception-caught self.fail(f"Error inspecting image ID {image_id} - {exc}") return inspection @@ -567,7 +567,7 @@ class AnsibleDockerClientBase(Client): """ try: response = self.images(name=name) - except Exception as exc: + except Exception as exc: # pylint: disable=broad-exception-caught self.fail(f"Error searching for image {name} - {exc}") images = response if tag: @@ -606,7 +606,7 @@ class AnsibleDockerClientBase(Client): ) else: self.fail(f"Error pulling {name} - {line.get('error')}") - except Exception as exc: + except Exception as exc: # pylint: disable=broad-exception-caught self.fail(f"Error pulling image {name}:{tag} - {exc}") new_tag = self.find_image(name, tag) diff --git a/plugins/module_utils/_common_api.py b/plugins/module_utils/_common_api.py index 22753221..6e390e69 100644 --- a/plugins/module_utils/_common_api.py +++ b/plugins/module_utils/_common_api.py @@ -128,7 +128,7 @@ class AnsibleDockerClientBase(Client): ) except APIError as exc: self.fail(f"Docker API error: {exc}") - except Exception as exc: + except Exception as exc: # pylint: disable=broad-exception-caught self.fail(f"Error connecting: {exc}") self.docker_api_version = LooseVersion(self.docker_api_version_str) @@ -308,7 +308,7 @@ class AnsibleDockerClientBase(Client): return result except NotFound: return None - except Exception as exc: + except Exception as exc: # pylint: disable=broad-exception-caught self.fail(f"Error inspecting container: {exc}") def get_container(self, name=None): @@ -347,7 +347,7 @@ class AnsibleDockerClientBase(Client): break except SSLError as exc: self._handle_ssl_error(exc) - except Exception as exc: + except Exception as exc: # pylint: disable=broad-exception-caught self.fail(f"Error retrieving container list: {exc}") if result is None: @@ -377,7 +377,7 @@ class AnsibleDockerClientBase(Client): break except SSLError as exc: self._handle_ssl_error(exc) - except Exception as exc: + except Exception as exc: # pylint: disable=broad-exception-caught self.fail(f"Error retrieving network list: {exc}") if result is not None: @@ -390,7 +390,7 @@ class AnsibleDockerClientBase(Client): self.log("Completed network inspection") except NotFound: return None - except Exception as exc: + except Exception as exc: # pylint: disable=broad-exception-caught self.fail(f"Error inspecting network: {exc}") return result @@ -412,7 +412,7 @@ class AnsibleDockerClientBase(Client): else: params["filters"] = convert_filters({"reference": name}) images = self.get_json("/images/json", params=params) - except Exception as exc: + except Exception as exc: # pylint: disable=broad-exception-caught self.fail(f"Error searching for image {name} - {exc}") if tag: lookup = f"{name}:{tag}" @@ -472,7 +472,7 @@ class AnsibleDockerClientBase(Client): except NotFound: self.log(f"Image {name}:{tag} not found.") return None - except Exception as exc: + except Exception as exc: # pylint: disable=broad-exception-caught self.fail(f"Error inspecting image {name}:{tag} - {exc}") self.log(f"Image {name}:{tag} not found.") @@ -493,7 +493,7 @@ class AnsibleDockerClientBase(Client): self.fail(f"Error inspecting image ID {image_id} - {exc}") self.log(f"Image {image_id} not found.") return None - except Exception as exc: + except Exception as exc: # pylint: disable=broad-exception-caught self.fail(f"Error inspecting image ID {image_id} - {exc}") def pull_image(self, name, tag="latest", image_platform=None): @@ -535,7 +535,7 @@ class AnsibleDockerClientBase(Client): ) else: self.fail(f"Error pulling {name} - {line.get('error')}") - except Exception as exc: + except Exception as exc: # pylint: disable=broad-exception-caught self.fail(f"Error pulling image {name}:{tag} - {exc}") new_tag = self.find_image(name, tag) diff --git a/plugins/module_utils/_common_cli.py b/plugins/module_utils/_common_cli.py index d3fdfe24..81006d8e 100644 --- a/plugins/module_utils/_common_cli.py +++ b/plugins/module_utils/_common_cli.py @@ -159,7 +159,7 @@ class AnsibleDockerClientBase: self.warn(to_native(stderr)) try: data = json.loads(stdout) - except Exception as exc: + except Exception as exc: # pylint: disable=broad-exception-caught self.fail( f"Error while parsing JSON output of {self._compose_cmd_str(args)}: {exc}\nJSON output: {to_native(stdout)}" ) @@ -177,7 +177,7 @@ class AnsibleDockerClientBase: line = line.strip() if line.startswith(b"{"): result.append(json.loads(line)) - except Exception as exc: + except Exception as exc: # pylint: disable=broad-exception-caught self.fail( f"Error while parsing JSON output of {self._compose_cmd_str(args)}: {exc}\nJSON output: {to_native(stdout)}" ) diff --git a/plugins/module_utils/_compose_v2.py b/plugins/module_utils/_compose_v2.py index f18b2eae..e52b0a16 100644 --- a/plugins/module_utils/_compose_v2.py +++ b/plugins/module_utils/_compose_v2.py @@ -405,7 +405,7 @@ def parse_json_events(stderr, warn_function=None): continue try: line_data = json.loads(line) - except Exception as exc: + except Exception as exc: # pylint: disable=broad-exception-caught if warn_function: warn_function( f"Cannot parse event from line: {line!r}: {exc}. Please report this at " @@ -748,7 +748,7 @@ class BaseComposeManager(DockerBaseClass): encoding="utf-8", Dumper=_SafeDumper, ) - except Exception as exc: + except Exception as exc: # pylint: disable=broad-exception-caught self.fail(f"Error writing to {compose_file} - {exc}") else: self.project_src = os.path.abspath(parameters["project_src"]) @@ -804,7 +804,7 @@ class BaseComposeManager(DockerBaseClass): if version == "dev": return None return version.lstrip("v") - except Exception: + except Exception: # pylint: disable=broad-exception-caught return None def get_compose_version_from_api(self): @@ -946,6 +946,6 @@ class BaseComposeManager(DockerBaseClass): for directory in self.cleanup_dirs: try: shutil.rmtree(directory, True) - except Exception: + except Exception: # pylint: disable=broad-exception-caught # should not happen, but simply ignore to be on the safe side pass diff --git a/plugins/module_utils/_module_container/base.py b/plugins/module_utils/_module_container/base.py index 861e9b33..460ed468 100644 --- a/plugins/module_utils/_module_container/base.py +++ b/plugins/module_utils/_module_container/base.py @@ -431,7 +431,7 @@ def _parse_port_range(range_or_port, module): if "-" in range_or_port: try: start, end = [int(port) for port in range_or_port.split("-")] - except Exception: + except ValueError: module.fail_json(msg=f'Invalid port range: "{range_or_port}"') if end < start: module.fail_json(msg=f'Invalid port range: "{range_or_port}"') @@ -439,7 +439,7 @@ def _parse_port_range(range_or_port, module): else: try: return [int(range_or_port)] - except Exception: + except ValueError: module.fail_json(msg=f'Invalid port: "{range_or_port}"') @@ -707,7 +707,7 @@ def _preprocess_mounts(module, values): if mount_dict["tmpfs_mode"] is not None: try: mount_dict["tmpfs_mode"] = int(mount_dict["tmpfs_mode"], 8) - except Exception: + except ValueError: module.fail_json( msg=f'tmp_fs mode of mount "{target}" is not an octal string!' ) diff --git a/plugins/module_utils/_module_container/docker_api.py b/plugins/module_utils/_module_container/docker_api.py index 1ccfa229..1b5b20ea 100644 --- a/plugins/module_utils/_module_container/docker_api.py +++ b/plugins/module_utils/_module_container/docker_api.py @@ -1060,7 +1060,7 @@ def _get_network_id(module, client, network_name): network_id = network["Id"] break return network_id - except Exception as exc: + except Exception as exc: # pylint: disable=broad-exception-caught client.fail(f"Error getting network id for {network_name} - {exc}") diff --git a/plugins/module_utils/_module_container/module.py b/plugins/module_utils/_module_container/module.py index 8353622d..20d6ced7 100644 --- a/plugins/module_utils/_module_container/module.py +++ b/plugins/module_utils/_module_container/module.py @@ -481,7 +481,7 @@ class ContainerManager(DockerBaseClass): self.engine_driver.unpause_container( self.client, container.id ) - except Exception as exc: + except Exception as exc: # pylint: disable=broad-exception-caught self.fail( f"Error {'pausing' if self.param_paused else 'unpausing'} container {container.id}: {exc}" ) @@ -951,7 +951,7 @@ class ContainerManager(DockerBaseClass): self.engine_driver.disconnect_container_from_network( self.client, container.id, diff["parameter"]["id"] ) - except Exception as exc: + except Exception as exc: # pylint: disable=broad-exception-caught self.fail( f"Error disconnecting container from network {diff['parameter']['name']} - {exc}" ) @@ -976,7 +976,7 @@ class ContainerManager(DockerBaseClass): self.engine_driver.connect_container_to_network( self.client, container.id, diff["parameter"]["id"], params ) - except Exception as exc: + except Exception as exc: # pylint: disable=broad-exception-caught self.fail( f"Error connecting container to network {diff['parameter']['name']} - {exc}" ) @@ -990,7 +990,7 @@ class ContainerManager(DockerBaseClass): self.engine_driver.disconnect_container_from_network( self.client, container.id, network["name"] ) - except Exception as exc: + except Exception as exc: # pylint: disable=broad-exception-caught self.fail( f"Error disconnecting container from network {network['name']} - {exc}" ) @@ -1028,7 +1028,7 @@ class ContainerManager(DockerBaseClass): container_id = self.engine_driver.create_container( self.client, self.param_name, create_parameters, networks=networks ) - except Exception as exc: + except Exception as exc: # pylint: disable=broad-exception-caught self.fail(f"Error creating container: {exc}") return self._get_container(container_id) return new_container @@ -1040,7 +1040,7 @@ class ContainerManager(DockerBaseClass): if not self.check_mode: try: self.engine_driver.start_container(self.client, container_id) - except Exception as exc: + except Exception as exc: # pylint: disable=broad-exception-caught self.fail(f"Error starting container {container_id}: {exc}") if self.module.params["detach"] is False: @@ -1097,7 +1097,7 @@ class ContainerManager(DockerBaseClass): link=link, force=force, ) - except Exception as exc: + except Exception as exc: # pylint: disable=broad-exception-caught self.client.fail(f"Error removing container {container_id}: {exc}") def container_update(self, container_id, update_parameters): @@ -1113,7 +1113,7 @@ class ContainerManager(DockerBaseClass): self.engine_driver.update_container( self.client, container_id, update_parameters ) - except Exception as exc: + except Exception as exc: # pylint: disable=broad-exception-caught self.fail(f"Error updating container {container_id}: {exc}") return self._get_container(container_id) @@ -1127,7 +1127,7 @@ class ContainerManager(DockerBaseClass): self.engine_driver.kill_container( self.client, container_id, kill_signal=self.param_kill_signal ) - except Exception as exc: + except Exception as exc: # pylint: disable=broad-exception-caught self.fail(f"Error killing container {container_id}: {exc}") def container_restart(self, container_id): @@ -1140,7 +1140,7 @@ class ContainerManager(DockerBaseClass): self.engine_driver.restart_container( self.client, container_id, self.module.params["stop_timeout"] or 10 ) - except Exception as exc: + except Exception as exc: # pylint: disable=broad-exception-caught self.fail(f"Error restarting container {container_id}: {exc}") return self._get_container(container_id) @@ -1157,7 +1157,7 @@ class ContainerManager(DockerBaseClass): self.engine_driver.stop_container( self.client, container_id, self.module.params["stop_timeout"] ) - except Exception as exc: + except Exception as exc: # pylint: disable=broad-exception-caught self.fail(f"Error stopping container {container_id}: {exc}") diff --git a/plugins/module_utils/_socket_handler.py b/plugins/module_utils/_socket_handler.py index 8630b923..60bae997 100644 --- a/plugins/module_utils/_socket_handler.py +++ b/plugins/module_utils/_socket_handler.py @@ -78,7 +78,7 @@ class DockerSocketHandlerBase: if hasattr(self._sock, "recv"): try: data = self._sock.recv(262144) - except Exception as e: + except Exception as e: # pylint: disable=broad-exception-caught # After calling self._sock.shutdown(), OpenSSL's/urllib3's # WrappedSocket seems to eventually raise ZeroReturnError in # case of EOF diff --git a/plugins/module_utils/_swarm.py b/plugins/module_utils/_swarm.py index 34a6f4ef..c83b11c0 100644 --- a/plugins/module_utils/_swarm.py +++ b/plugins/module_utils/_swarm.py @@ -179,7 +179,7 @@ class AnsibleDockerSwarmClient(AnsibleDockerClient): if skip_missing: return None self.fail(f"Error while reading from Swarm manager: {exc}") - except Exception as exc: + except Exception as exc: # pylint: disable=broad-exception-caught self.fail(f"Error inspecting swarm node: {exc}") json_str = json.dumps(node_info, ensure_ascii=False) @@ -215,7 +215,7 @@ class AnsibleDockerSwarmClient(AnsibleDockerClient): "Cannot inspect node: To inspect node execute module on Swarm Manager" ) self.fail(f"Error while reading from Swarm manager: {exc}") - except Exception as exc: + except Exception as exc: # pylint: disable=broad-exception-caught self.fail(f"Error inspecting swarm node: {exc}") json_str = json.dumps(node_info, ensure_ascii=False) @@ -295,7 +295,7 @@ class AnsibleDockerSwarmClient(AnsibleDockerClient): "Cannot inspect service: To inspect service execute module on Swarm Manager" ) self.fail(f"Error inspecting swarm service: {exc}") - except Exception as exc: + except Exception as exc: # pylint: disable=broad-exception-caught self.fail(f"Error inspecting swarm service: {exc}") json_str = json.dumps(service_info, ensure_ascii=False) diff --git a/plugins/modules/docker_config.py b/plugins/modules/docker_config.py index 1af51533..b494095d 100644 --- a/plugins/modules/docker_config.py +++ b/plugins/modules/docker_config.py @@ -243,7 +243,7 @@ class ConfigManager(DockerBaseClass): try: with open(data_src, "rb") as f: self.data = f.read() - except Exception as exc: + except Exception as exc: # pylint: disable=broad-exception-caught self.client.fail(f"Error while reading {data_src}: {exc}") self.labels = parameters.get("labels") self.force = parameters.get("force") diff --git a/plugins/modules/docker_container_copy_into.py b/plugins/modules/docker_container_copy_into.py index 86159d88..bfdbf8f3 100644 --- a/plugins/modules/docker_container_copy_into.py +++ b/plugins/modules/docker_container_copy_into.py @@ -1084,9 +1084,7 @@ def main(): if client.module.params["content_is_b64"]: try: content = base64.b64decode(content) - except ( - Exception - ) as e: # depending on Python version and error, multiple different exceptions can be raised + except Exception as e: # pylint: disable=broad-exception-caught client.fail(f"Cannot Base64 decode the content option: {e}") else: content = to_bytes(content) diff --git a/plugins/modules/docker_image.py b/plugins/modules/docker_image.py index ddc607b4..5448e12a 100644 --- a/plugins/modules/docker_image.py +++ b/plugins/modules/docker_image.py @@ -618,7 +618,7 @@ class ImageManager(DockerBaseClass): except NotFound: # If the image vanished while we were trying to remove it, do not fail pass - except Exception as exc: + except Exception as exc: # pylint: disable=broad-exception-caught self.fail(f"Error removing image {name} - {exc}") self.results["changed"] = True @@ -714,14 +714,14 @@ class ImageManager(DockerBaseClass): DEFAULT_DATA_CHUNK_SIZE, False, ) - except Exception as exc: + except Exception as exc: # pylint: disable=broad-exception-caught self.fail(f"Error getting image {image_name} - {exc}") try: with open(self.archive_path, "wb") as fd: for chunk in saved_image: fd.write(chunk) - except Exception as exc: + except Exception as exc: # pylint: disable=broad-exception-caught self.fail(f"Error writing image archive {self.archive_path} - {exc}") self.results["image"] = image @@ -784,7 +784,7 @@ class ImageManager(DockerBaseClass): if status == "Pushing": changed = True self.results["changed"] = changed - except Exception as exc: + except Exception as exc: # pylint: disable=broad-exception-caught if "unauthorized" in str(exc): if "authentication required" in str(exc): self.fail( @@ -843,7 +843,7 @@ class ImageManager(DockerBaseClass): self.client._raise_for_status(res) if res.status_code != 201: raise RuntimeError("Tag operation failed.") - except Exception as exc: + except Exception as exc: # pylint: disable=broad-exception-caught self.fail(f"Error: failed to tag image - {exc}") self.results["image"] = self.client.find_image(name=repo, tag=repo_tag) if image and image["Id"] == self.results["image"]["Id"]: @@ -1019,7 +1019,7 @@ class ImageManager(DockerBaseClass): f"Error loading image {self.name} - {exc}", stdout="\n".join(load_output), ) - except Exception as exc: + except Exception as exc: # pylint: disable=broad-exception-caught self.client.fail( f"Error loading image {self.name} - {exc}", stdout="\n".join(load_output), diff --git a/plugins/modules/docker_image_export.py b/plugins/modules/docker_image_export.py index 1f856a38..eb32f9a4 100644 --- a/plugins/modules/docker_image_export.py +++ b/plugins/modules/docker_image_export.py @@ -189,7 +189,7 @@ class ImageExportManager(DockerBaseClass): with open(self.path, "wb") as fd: for chunk in chunks: fd.write(chunk) - except Exception as exc: + except Exception as exc: # pylint: disable=broad-exception-caught self.fail(f"Error writing image archive {self.path} - {exc}") def export_images(self): @@ -205,7 +205,7 @@ class ImageExportManager(DockerBaseClass): DEFAULT_DATA_CHUNK_SIZE, False, ) - except Exception as exc: + except Exception as exc: # pylint: disable=broad-exception-caught self.fail(f"Error getting image {image_names[0]} - {exc}") else: self.log(f"Getting archive of images {image_names_str}") @@ -219,7 +219,7 @@ class ImageExportManager(DockerBaseClass): DEFAULT_DATA_CHUNK_SIZE, False, ) - except Exception as exc: + except Exception as exc: # pylint: disable=broad-exception-caught self.fail(f"Error getting images {image_names_str} - {exc}") self.write_chunks(chunks) diff --git a/plugins/modules/docker_image_info.py b/plugins/modules/docker_image_info.py index 9b5f5322..a9ca0405 100644 --- a/plugins/modules/docker_image_info.py +++ b/plugins/modules/docker_image_info.py @@ -212,7 +212,7 @@ class ImageManager(DockerBaseClass): inspection = self.client.get_json("/images/{0}/json", image["Id"]) except NotFound: inspection = None - except Exception as exc: + except Exception as exc: # pylint: disable=broad-exception-caught self.fail(f"Error inspecting image {image['Id']} - {exc}") results.append(inspection) return results diff --git a/plugins/modules/docker_image_load.py b/plugins/modules/docker_image_load.py index 0b1d96b8..e49a5b4c 100644 --- a/plugins/modules/docker_image_load.py +++ b/plugins/modules/docker_image_load.py @@ -141,7 +141,7 @@ class ImageManager(DockerBaseClass): f"Error loading archive {self.path} - {exc}", stdout="\n".join(load_output), ) - except Exception as exc: + except Exception as exc: # pylint: disable=broad-exception-caught self.client.fail( f"Error loading archive {self.path} - {exc}", stdout="\n".join(load_output), diff --git a/plugins/modules/docker_image_push.py b/plugins/modules/docker_image_push.py index 507fdb34..a6d711b2 100644 --- a/plugins/modules/docker_image_push.py +++ b/plugins/modules/docker_image_push.py @@ -159,7 +159,7 @@ class ImagePusher(DockerBaseClass): status = line.get("status") if status == "Pushing": results["changed"] = True - except Exception as exc: + except Exception as exc: # pylint: disable=broad-exception-caught if "unauthorized" in str(exc): if "authentication required" in str(exc): self.client.fail( diff --git a/plugins/modules/docker_image_remove.py b/plugins/modules/docker_image_remove.py index 97ceaf4f..ca2d7569 100644 --- a/plugins/modules/docker_image_remove.py +++ b/plugins/modules/docker_image_remove.py @@ -194,7 +194,7 @@ class ImageRemover(DockerBaseClass): except NotFound: # If the image vanished while we were trying to remove it, do not fail res = [] - except Exception as exc: + except Exception as exc: # pylint: disable=broad-exception-caught self.fail(f"Error removing image {name} - {exc}") for entry in res: diff --git a/plugins/modules/docker_image_tag.py b/plugins/modules/docker_image_tag.py index 799af3f4..d27553ac 100644 --- a/plugins/modules/docker_image_tag.py +++ b/plugins/modules/docker_image_tag.py @@ -215,7 +215,7 @@ class ImageTagger(DockerBaseClass): self.client._raise_for_status(res) if res.status_code != 201: raise RuntimeError("Tag operation failed.") - except Exception as exc: + except Exception as exc: # pylint: disable=broad-exception-caught self.fail(f"Error: failed to tag image as {name}:{tag} - {exc}") return True, msg, tagged_image diff --git a/plugins/modules/docker_login.py b/plugins/modules/docker_login.py index e1e1c2d2..9de88be0 100644 --- a/plugins/modules/docker_login.py +++ b/plugins/modules/docker_login.py @@ -309,7 +309,7 @@ class LoginManager(DockerBaseClass): self.log(f"Log into {self.registry_url} with username {self.username}") try: response = self._login(self.reauthorize) - except Exception as exc: + except Exception as exc: # pylint: disable=broad-exception-caught self.fail( f"Logging into {self.registry_url} for user {self.username} failed - {exc}" ) @@ -322,7 +322,7 @@ class LoginManager(DockerBaseClass): if not self.reauthorize and response["password"] != self.password: try: response = self._login(True) - except Exception as exc: + except Exception as exc: # pylint: disable=broad-exception-caught self.fail( f"Logging into {self.registry_url} for user {self.username} failed - {exc}" ) diff --git a/plugins/modules/docker_secret.py b/plugins/modules/docker_secret.py index d4e20f11..378876a0 100644 --- a/plugins/modules/docker_secret.py +++ b/plugins/modules/docker_secret.py @@ -235,7 +235,7 @@ class SecretManager(DockerBaseClass): try: with open(data_src, "rb") as f: self.data = f.read() - except Exception as exc: + except Exception as exc: # pylint: disable=broad-exception-caught self.client.fail(f"Error while reading {data_src}: {exc}") self.labels = parameters.get("labels") self.force = parameters.get("force") diff --git a/plugins/modules/docker_swarm_service.py b/plugins/modules/docker_swarm_service.py index 4a451417..a2a7635a 100644 --- a/plugins/modules/docker_swarm_service.py +++ b/plugins/modules/docker_swarm_service.py @@ -2510,7 +2510,7 @@ class DockerServiceManager: try: current_service = self.get_service(module.params["name"]) - except Exception as e: + except Exception as e: # pylint: disable=broad-exception-caught self.client.fail( f"Error looking for service named {module.params['name']}: {e}" ) @@ -2527,7 +2527,7 @@ class DockerServiceManager: network_ids, self.client, ) - except Exception as e: + except Exception as e: # pylint: disable=broad-exception-caught return self.client.fail(f"Error parsing module parameters: {e}") changed = False diff --git a/plugins/modules/docker_volume_info.py b/plugins/modules/docker_volume_info.py index e051bd77..e0f99a50 100644 --- a/plugins/modules/docker_volume_info.py +++ b/plugins/modules/docker_volume_info.py @@ -87,7 +87,7 @@ def get_existing_volume(client, volume_name): return client.get_json("/volumes/{0}", volume_name) except NotFound: return None - except Exception as exc: + except Exception as exc: # pylint: disable=broad-exception-caught client.fail(f"Error inspecting volume: {exc}")