Include exception when reraising inside except (#109706)

This commit is contained in:
Marc Mueller 2024-02-06 12:17:39 +01:00 committed by GitHub
parent 6701806ed2
commit 5de76c0be0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 14 additions and 14 deletions

View File

@ -83,8 +83,8 @@ class ComelitBaseCoordinator(DataUpdateCoordinator[dict[str, Any]]):
return await self._async_update_system_data() return await self._async_update_system_data()
except (exceptions.CannotConnect, exceptions.CannotRetrieveData) as err: except (exceptions.CannotConnect, exceptions.CannotRetrieveData) as err:
raise UpdateFailed(repr(err)) from err raise UpdateFailed(repr(err)) from err
except exceptions.CannotAuthenticate: except exceptions.CannotAuthenticate as err:
raise ConfigEntryAuthFailed raise ConfigEntryAuthFailed from err
@abstractmethod @abstractmethod
async def _async_update_system_data(self) -> dict[str, Any]: async def _async_update_system_data(self) -> dict[str, Any]:

View File

@ -106,9 +106,9 @@ async def test_host_connection(
try: try:
await hass.async_add_executor_job(lupupy.Lupusec, username, password, host) 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) _LOGGER.error("Failed to connect to Lupusec device at %s", host)
raise CannotConnect raise CannotConnect from ex
class CannotConnect(HomeAssistantError): class CannotConnect(HomeAssistantError):

View File

@ -124,7 +124,7 @@ async def setup_device(
coordinator.api.is_available = True coordinator.api.is_available = True
try: try:
await coordinator.async_config_entry_first_refresh() await coordinator.async_config_entry_first_refresh()
except ConfigEntryNotReady: except ConfigEntryNotReady as ex:
if isinstance(coordinator.api, RoborockMqttClient): if isinstance(coordinator.api, RoborockMqttClient):
_LOGGER.warning( _LOGGER.warning(
"Not setting up %s because the we failed to get data for the first time using the online client. " "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. # but in case if it isn't, the error can be included in debug logs for the user to grab.
if coordinator.last_exception: if coordinator.last_exception:
_LOGGER.debug(coordinator.last_exception) _LOGGER.debug(coordinator.last_exception)
raise coordinator.last_exception raise coordinator.last_exception from ex
elif coordinator.last_exception: elif coordinator.last_exception:
# If this is reached, we have verified that we can communicate with the Vacuum locally, # 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 # 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, device.name,
extra_error, extra_error,
) )
raise coordinator.last_exception raise coordinator.last_exception from ex
return coordinator return coordinator

View File

@ -28,8 +28,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
if not client.check_credentials(): if not client.check_credentials():
raise ConfigEntryError raise ConfigEntryError
return client return client
except PySuezError: except PySuezError as ex:
raise ConfigEntryNotReady raise ConfigEntryNotReady from ex
hass.data.setdefault(DOMAIN, {})[ hass.data.setdefault(DOMAIN, {})[
entry.entry_id entry.entry_id

View File

@ -40,8 +40,8 @@ def validate_input(data: dict[str, Any]) -> None:
) )
if not client.check_credentials(): if not client.check_credentials():
raise InvalidAuth raise InvalidAuth
except PySuezError: except PySuezError as ex:
raise CannotConnect raise CannotConnect from ex
class SuezWaterConfigFlow(ConfigFlow, domain=DOMAIN): class SuezWaterConfigFlow(ConfigFlow, domain=DOMAIN):

View File

@ -2202,8 +2202,8 @@ class FirmwareUploadView(HomeAssistantView):
node = async_get_node_from_device_id(hass, device_id, self._dev_reg) node = async_get_node_from_device_id(hass, device_id, self._dev_reg)
except ValueError as err: except ValueError as err:
if "not loaded" in err.args[0]: if "not loaded" in err.args[0]:
raise web_exceptions.HTTPBadRequest raise web_exceptions.HTTPBadRequest from err
raise web_exceptions.HTTPNotFound raise web_exceptions.HTTPNotFound from err
# If this was not true, we wouldn't have been able to get the node from the # If this was not true, we wouldn't have been able to get the node from the
# device ID above # device ID above

View File

@ -2249,7 +2249,7 @@ async def _load_integration(
domain, domain,
err, err,
) )
raise data_entry_flow.UnknownHandler raise data_entry_flow.UnknownHandler from err
async def _async_get_flow_handler( async def _async_get_flow_handler(