Handle BaseException from asyncio gather (#103814)

pull/103827/head
Marc Mueller 2023-11-11 22:26:37 +01:00 committed by GitHub
parent bf41167951
commit c35f56ea77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 12 additions and 4 deletions

View File

@ -63,6 +63,8 @@ async def async_discover_devices(
if isinstance(discovered, Exception):
_LOGGER.debug("Scanning %s failed with error: %s", targets[idx], discovered)
continue
if isinstance(discovered, BaseException):
raise discovered from None
for device in discovered:
assert isinstance(device, ElkSystem)
combined_discoveries[device.ip_address] = device

View File

@ -189,6 +189,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
raise UpdateFailed(
f"There was an unknown error while updating {attr}: {result}"
) from result
if isinstance(result, BaseException):
raise result from None
data.update_data_from_response(result)

View File

@ -33,6 +33,8 @@ async def async_discover_devices(
if isinstance(discovered, Exception):
_LOGGER.debug("Scanning %s failed with error: %s", targets[idx], discovered)
continue
if isinstance(discovered, BaseException):
raise discovered from None
for device in discovered:
assert isinstance(device, DiscoveredBulb)
combined_discoveries[device.ip_address] = device

View File

@ -885,7 +885,7 @@ async def entity_service_call(
# Use asyncio.gather here to ensure the returned results
# are in the same order as the entities list
results: list[ServiceResponse] = await asyncio.gather(
results: list[ServiceResponse | BaseException] = await asyncio.gather(
*[
entity.async_request_call(
_handle_entity_call(hass, entity, func, data, call.context)
@ -897,8 +897,8 @@ async def entity_service_call(
response_data: EntityServiceResponse = {}
for entity, result in zip(entities, results):
if isinstance(result, Exception):
raise result
if isinstance(result, BaseException):
raise result from None
response_data[entity.entity_id] = result
tasks: list[asyncio.Task[None]] = []

View File

@ -305,7 +305,7 @@ async def async_initialize_triggers(
variables: TemplateVarsType = None,
) -> CALLBACK_TYPE | None:
"""Initialize triggers."""
triggers = []
triggers: list[Coroutine[Any, Any, CALLBACK_TYPE]] = []
for idx, conf in enumerate(trigger_config):
# Skip triggers that are not enabled
if not conf.get(CONF_ENABLED, True):
@ -338,6 +338,8 @@ async def async_initialize_triggers(
log_cb(logging.ERROR, f"Got error '{result}' when setting up triggers for")
elif isinstance(result, Exception):
log_cb(logging.ERROR, "Error setting up trigger", exc_info=result)
elif isinstance(result, BaseException):
raise result from None
elif result is None:
log_cb(
logging.ERROR, "Unknown error while setting up trigger (empty result)"