Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor BaseException into exception #3305

Merged
merged 5 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/watchmaker/status/providers/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
self.region = self.__get_response_from_server(
self.metadata_region_url
)
except BaseException as ex:
except Exception as ex: # pylint: disable=broad-exception-caught
self.logger.error(
"Error retrieving id/region from metadata service %s", ex
)
Expand All @@ -69,7 +69,7 @@
try:
self.__tag_aws_instance(key, status)
return
except BaseException as ex:
except Exception as ex: # pylint: disable=broad-exception-caught

Check warning on line 72 in src/watchmaker/status/providers/aws.py

View check run for this annotation

Codecov / codecov/patch

src/watchmaker/status/providers/aws.py#L72

Added line #L72 was not covered by tests
logging.error("Exception while tagging aws instance %s", ex)
self.__error_on_required_status(required)

Expand Down
4 changes: 2 additions & 2 deletions src/watchmaker/status/providers/azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

try:
self.__set_ids_from_server()
except BaseException as ex:
except Exception as ex: # pylint: disable=broad-exception-caught

Check warning on line 43 in src/watchmaker/status/providers/azure.py

View check run for this annotation

Codecov / codecov/patch

src/watchmaker/status/providers/azure.py#L43

Added line #L43 was not covered by tests
self.logger.error(
"Error retrieving ids from metadata service %s", ex
)
Expand All @@ -52,7 +52,7 @@
try:
self.__tag_azure_resouce(key, status)
return
except BaseException as ex:
except Exception as ex: # pylint: disable=broad-exception-caught

Check warning on line 55 in src/watchmaker/status/providers/azure.py

View check run for this annotation

Codecov / codecov/patch

src/watchmaker/status/providers/azure.py#L55

Added line #L55 was not covered by tests
logging.error("Exception while tagging azure resource %s", ex)
self.__error_on_required_status(required)

Expand Down
6 changes: 3 additions & 3 deletions src/watchmaker/utils/imds/detect/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

def provider(supported_providers=None):
"""Identify and return identifier."""
exception_list = []
results = []
futures = []
supported_providers = supported_providers if supported_providers else []
Expand All @@ -46,8 +45,8 @@
results.append(fut.result())
except InvalidProviderError:
pass
except BaseException as ex:
exception_list.append(str(ex))
except Exception: # pylint: disable=broad-exception-caught
log.error("Unexpected exception occurred", exc_info=True)

Check warning on line 49 in src/watchmaker/utils/imds/detect/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/watchmaker/utils/imds/detect/__init__.py#L48-L49

Added lines #L48 - L49 were not covered by tests

if len(results) > 1:
raise CloudDetectError("Detected more than one cloud provider")
Expand All @@ -64,6 +63,7 @@
if cloud_provider_instance.identify():
return cloud_provider_instance

log.debug("Environment is not %s", cloud_provider_instance.identifier)
raise InvalidProviderError(
"Environment is not %s" % cloud_provider_instance.identifier
)
4 changes: 2 additions & 2 deletions src/watchmaker/utils/imds/detect/providers/aws_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
self.logger.debug("Checking AWS metadata")
try:
return self.__is_valid_server()
except BaseException as ex:
except Exception as ex: # pylint: disable=broad-exception-caught

Check warning on line 48 in src/watchmaker/utils/imds/detect/providers/aws_provider.py

View check run for this annotation

Codecov / codecov/patch

src/watchmaker/utils/imds/detect/providers/aws_provider.py#L48

Added line #L48 was not covered by tests
self.logger.error(ex)
return False

Expand Down Expand Up @@ -87,7 +87,7 @@
},
method="PUT",
)
except BaseException as error:
except Exception as error: # pylint: disable=broad-exception-caught

Check warning on line 90 in src/watchmaker/utils/imds/detect/providers/aws_provider.py

View check run for this annotation

Codecov / codecov/patch

src/watchmaker/utils/imds/detect/providers/aws_provider.py#L90

Added line #L90 was not covered by tests
self.logger.debug("Failed to set IMDSv2 token: %s", error)
return None

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
self.logger.debug("Checking Azure metadata")
try:
return self.__is_valid_server()
except BaseException as ex:
except Exception as ex: # pylint: disable=broad-exception-caught

Check warning on line 39 in src/watchmaker/utils/imds/detect/providers/azure_provider.py

View check run for this annotation

Codecov / codecov/patch

src/watchmaker/utils/imds/detect/providers/azure_provider.py#L39

Added line #L39 was not covered by tests
self.logger.warning("Error while checking server %s", str(ex))
return False

Expand Down
Loading