From 3079f126a855c48adc00c92e8ff29eca8227b3a1 Mon Sep 17 00:00:00 2001 From: karwosts <32912880+karwosts@users.noreply.github.com> Date: Mon, 16 Sep 2024 08:55:16 -0700 Subject: [PATCH] Improve robustness of automation editor description error handling (#21993) --- src/data/automation_i18n.ts | 26 ++++++++++++++++++++++---- src/data/script_i18n.ts | 6 +++++- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/data/automation_i18n.ts b/src/data/automation_i18n.ts index 908c37954cbf..f6bc8b208fba 100644 --- a/src/data/automation_i18n.ts +++ b/src/data/automation_i18n.ts @@ -68,9 +68,18 @@ export const describeTrigger = ( hass: HomeAssistant, entityRegistry: EntityRegistryEntry[], ignoreAlias = false -) => { +): string => { try { - return tryDescribeTrigger(trigger, hass, entityRegistry, ignoreAlias); + const description = tryDescribeTrigger( + trigger, + hass, + entityRegistry, + ignoreAlias + ); + if (typeof description !== "string") { + throw new Error(String(description)); + } + return description; } catch (error: any) { // eslint-disable-next-line no-console console.error(error); @@ -700,9 +709,18 @@ export const describeCondition = ( hass: HomeAssistant, entityRegistry: EntityRegistryEntry[], ignoreAlias = false -) => { +): string => { try { - return tryDescribeCondition(condition, hass, entityRegistry, ignoreAlias); + const description = tryDescribeCondition( + condition, + hass, + entityRegistry, + ignoreAlias + ); + if (typeof description !== "string") { + throw new Error(String(description)); + } + return description; } catch (error: any) { // eslint-disable-next-line no-console console.error(error); diff --git a/src/data/script_i18n.ts b/src/data/script_i18n.ts index 64852bc6e779..b623aba7dba5 100644 --- a/src/data/script_i18n.ts +++ b/src/data/script_i18n.ts @@ -50,7 +50,7 @@ export const describeAction = ( ignoreAlias = false ): string => { try { - return tryDescribeAction( + const description = tryDescribeAction( hass, entityRegistry, labelRegistry, @@ -59,6 +59,10 @@ export const describeAction = ( actionType, ignoreAlias ); + if (typeof description !== "string") { + throw new Error(String(description)); + } + return description; } catch (error: any) { // eslint-disable-next-line no-console console.error(error);