From 0bc597f8c74565896ad4fc9f8c8e45003e16fcf0 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Wed, 26 Jun 2024 02:13:09 +0200 Subject: [PATCH] Improve vol.Invalid handling (#120480) --- homeassistant/components/blueprint/errors.py | 2 +- homeassistant/components/logbook/rest_api.py | 4 ++-- homeassistant/components/mqtt/mixins.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/blueprint/errors.py b/homeassistant/components/blueprint/errors.py index 221279a39ac..e9a9defe05a 100644 --- a/homeassistant/components/blueprint/errors.py +++ b/homeassistant/components/blueprint/errors.py @@ -47,7 +47,7 @@ class InvalidBlueprint(BlueprintWithNameException): domain: str | None, blueprint_name: str | None, blueprint_data: Any, - msg_or_exc: vol.Invalid, + msg_or_exc: str | vol.Invalid, ) -> None: """Initialize an invalid blueprint error.""" if isinstance(msg_or_exc, vol.Invalid): diff --git a/homeassistant/components/logbook/rest_api.py b/homeassistant/components/logbook/rest_api.py index 5f1918ebccf..bd9efe7aba3 100644 --- a/homeassistant/components/logbook/rest_api.py +++ b/homeassistant/components/logbook/rest_api.py @@ -70,11 +70,11 @@ class LogbookView(HomeAssistantView): if entity_ids_str := request.query.get("entity"): try: entity_ids = cv.entity_ids(entity_ids_str) - except vol.Invalid: + except vol.Invalid as ex: raise InvalidEntityFormatError( f"Invalid entity id(s) encountered: {entity_ids_str}. " "Format should be ." - ) from vol.Invalid + ) from ex else: entity_ids = None diff --git a/homeassistant/components/mqtt/mixins.py b/homeassistant/components/mqtt/mixins.py index 0800aeb8ee4..aca88f2cb97 100644 --- a/homeassistant/components/mqtt/mixins.py +++ b/homeassistant/components/mqtt/mixins.py @@ -157,7 +157,7 @@ class SetupEntity(Protocol): @callback def async_handle_schema_error( - discovery_payload: MQTTDiscoveryPayload, err: vol.MultipleInvalid + discovery_payload: MQTTDiscoveryPayload, err: vol.Invalid ) -> None: """Help handling schema errors on MQTT discovery messages.""" discovery_topic: str = discovery_payload.discovery_data[ATTR_DISCOVERY_TOPIC]