From 5de76c0be03eefef187b28afac719e2c02c7efde Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Tue, 6 Feb 2024 12:17:39 +0100 Subject: [PATCH] Include exception when reraising inside except (#109706) --- homeassistant/components/comelit/coordinator.py | 4 ++-- homeassistant/components/lupusec/config_flow.py | 4 ++-- homeassistant/components/roborock/__init__.py | 6 +++--- homeassistant/components/suez_water/__init__.py | 4 ++-- homeassistant/components/suez_water/config_flow.py | 4 ++-- homeassistant/components/zwave_js/api.py | 4 ++-- homeassistant/config_entries.py | 2 +- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/homeassistant/components/comelit/coordinator.py b/homeassistant/components/comelit/coordinator.py index 4ff75ba5307..fe23cb1f5d3 100644 --- a/homeassistant/components/comelit/coordinator.py +++ b/homeassistant/components/comelit/coordinator.py @@ -83,8 +83,8 @@ class ComelitBaseCoordinator(DataUpdateCoordinator[dict[str, Any]]): return await self._async_update_system_data() except (exceptions.CannotConnect, exceptions.CannotRetrieveData) as err: raise UpdateFailed(repr(err)) from err - except exceptions.CannotAuthenticate: - raise ConfigEntryAuthFailed + except exceptions.CannotAuthenticate as err: + raise ConfigEntryAuthFailed from err @abstractmethod async def _async_update_system_data(self) -> dict[str, Any]: diff --git a/homeassistant/components/lupusec/config_flow.py b/homeassistant/components/lupusec/config_flow.py index aad57897c91..1fae687cbdb 100644 --- a/homeassistant/components/lupusec/config_flow.py +++ b/homeassistant/components/lupusec/config_flow.py @@ -106,9 +106,9 @@ async def test_host_connection( try: await hass.async_add_executor_job(lupupy.Lupusec, username, password, host) - except lupupy.LupusecException: + except lupupy.LupusecException as ex: _LOGGER.error("Failed to connect to Lupusec device at %s", host) - raise CannotConnect + raise CannotConnect from ex class CannotConnect(HomeAssistantError): diff --git a/homeassistant/components/roborock/__init__.py b/homeassistant/components/roborock/__init__.py index 0b4dfa29e78..e0dfb2b271f 100644 --- a/homeassistant/components/roborock/__init__.py +++ b/homeassistant/components/roborock/__init__.py @@ -124,7 +124,7 @@ async def setup_device( coordinator.api.is_available = True try: await coordinator.async_config_entry_first_refresh() - except ConfigEntryNotReady: + except ConfigEntryNotReady as ex: if isinstance(coordinator.api, RoborockMqttClient): _LOGGER.warning( "Not setting up %s because the we failed to get data for the first time using the online client. " @@ -136,7 +136,7 @@ async def setup_device( # but in case if it isn't, the error can be included in debug logs for the user to grab. if coordinator.last_exception: _LOGGER.debug(coordinator.last_exception) - raise coordinator.last_exception + raise coordinator.last_exception from ex elif coordinator.last_exception: # If this is reached, we have verified that we can communicate with the Vacuum locally, # so if there is an error here - it is not a communication issue but some other problem @@ -147,7 +147,7 @@ async def setup_device( device.name, extra_error, ) - raise coordinator.last_exception + raise coordinator.last_exception from ex return coordinator diff --git a/homeassistant/components/suez_water/__init__.py b/homeassistant/components/suez_water/__init__.py index 66c3981705c..02d78dfee41 100644 --- a/homeassistant/components/suez_water/__init__.py +++ b/homeassistant/components/suez_water/__init__.py @@ -28,8 +28,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: if not client.check_credentials(): raise ConfigEntryError return client - except PySuezError: - raise ConfigEntryNotReady + except PySuezError as ex: + raise ConfigEntryNotReady from ex hass.data.setdefault(DOMAIN, {})[ entry.entry_id diff --git a/homeassistant/components/suez_water/config_flow.py b/homeassistant/components/suez_water/config_flow.py index ba288c90e34..d01b8035a0c 100644 --- a/homeassistant/components/suez_water/config_flow.py +++ b/homeassistant/components/suez_water/config_flow.py @@ -40,8 +40,8 @@ def validate_input(data: dict[str, Any]) -> None: ) if not client.check_credentials(): raise InvalidAuth - except PySuezError: - raise CannotConnect + except PySuezError as ex: + raise CannotConnect from ex class SuezWaterConfigFlow(ConfigFlow, domain=DOMAIN): diff --git a/homeassistant/components/zwave_js/api.py b/homeassistant/components/zwave_js/api.py index 8d14c8ed5b6..5aa27ada977 100644 --- a/homeassistant/components/zwave_js/api.py +++ b/homeassistant/components/zwave_js/api.py @@ -2202,8 +2202,8 @@ class FirmwareUploadView(HomeAssistantView): node = async_get_node_from_device_id(hass, device_id, self._dev_reg) except ValueError as err: if "not loaded" in err.args[0]: - raise web_exceptions.HTTPBadRequest - raise web_exceptions.HTTPNotFound + raise web_exceptions.HTTPBadRequest from err + raise web_exceptions.HTTPNotFound from err # If this was not true, we wouldn't have been able to get the node from the # device ID above diff --git a/homeassistant/config_entries.py b/homeassistant/config_entries.py index b0a8f952b1b..4debdc8e495 100644 --- a/homeassistant/config_entries.py +++ b/homeassistant/config_entries.py @@ -2249,7 +2249,7 @@ async def _load_integration( domain, err, ) - raise data_entry_flow.UnknownHandler + raise data_entry_flow.UnknownHandler from err async def _async_get_flow_handler(