Repository: home-assistant/core
File: homeassistant/components/hassio/__init__.py (Python)

Code before:
            payload = data

        # Call API
        # The exceptions are logged properly in hassio.send_command
        with suppress(HassioAPIError):
            await hassio.send_command(
                api_endpoint.command.format(addon=addon, slug=slug),
                payload=payload,
                timeout=api_endpoint.timeout,
            )

    for service, settings in MAP_SERVICE_API.items():
        hass.services.async_register(
            DOMAIN, service, async_service_handler, schema=settings.schema
        )

    dev_reg = dr.async_get(hass)

    async def async_mount_reload(service: ServiceCall) -> None:
        """Handle service calls for Hass.io."""
        # These conditions are always true as they were verified by SCHEMA_MOUNT_RELOAD.
        if (device := dev_reg.async_get(service.data[ATTR_DEVICE_ID])) and device.name:
            try:
                await supervisor_client.mounts.reload_mount(device.name)
            except:
                _LOGGER.exception("Failed to reload mount %s", device.name)
                raise

    hass.services.async_register(
        DOMAIN, SERVICE_MOUNT_RELOAD, async_mount_reload, SCHEMA_MOUNT_RELOAD
    )

    async def update_info_data(_: datetime | None = None) -> None:
        """Update last available supervisor information."""
        supervisor_client = get_supervisor_client(hass)

        try:
            (
                hass.data[DATA_INFO],
                hass.data[DATA_HOST_INFO],
                store_info,
                hass.data[DATA_CORE_INFO],
                hass.data[DATA_SUPERVISOR_INFO],
                hass.data[DATA_OS_INFO],
                hass.data[DATA_NETWORK_INFO],
            ) = await asyncio.gather(
                create_eager_task(hassio.get_info()),
                create_eager_task(hassio.get_host_info()),
                create_eager_task(supervisor_client.store.info()),
                create_eager_task(hassio.get_core_info()),
                create_eager_task(hassio.get_supervisor_info()),

Review comment (suggestion):
It is not the goal to log them (and silently let everything happen). Instead we should re-raise it as a HomeAssistant error (including translation support).

Code after:

        # Call API
        # The exceptions are logged properly in hassio.send_command
        with suppress(HassioAPIError):
            await hassio.send_command(
                api_endpoint.command.format(addon=addon, slug=slug),
                payload=payload,
                timeout=api_endpoint.timeout,
            )

    for service, settings in MAP_SERVICE_API.items():
        hass.services.async_register(
            DOMAIN, service, async_service_handler, schema=settings.schema
        )

    dev_reg = dr.async_get(hass)

    async def async_mount_reload(service: ServiceCall) -> None:
        """Handle service calls for Hass.io."""
        coordinator: HassioDataUpdateCoordinator | None = None

        if (device := dev_reg.async_get(service.data[ATTR_DEVICE_ID])) is None:
            raise ServiceValidationError(
                translation_domain=DOMAIN,
                translation_key="mount_reload_unknown_device_id",
            )

        if (
            device.name is None
            or device.model != SupervisorEntityModel.MOUNT
            or (coordinator := hass.data.get(ADDONS_COORDINATOR)) is None
            or coordinator.entry_id not in device.config_entries
        ):
            raise ServiceValidationError(
                translation_domain=DOMAIN,
                translation_key="mount_reload_invalid_device",
            )

        try:
            await supervisor_client.mounts.reload_mount(device.name)
        except SupervisorError as error:
            raise HomeAssistantError(
                translation_domain=DOMAIN,
                translation_key="mount_reload_error",
                translation_placeholders={"name": device.name, "error": str(error)},
            ) from error

    hass.services.async_register(
        DOMAIN, SERVICE_MOUNT_RELOAD, async_mount_reload, SCHEMA_MOUNT_RELOAD
    )