From 5b8ca8d0ed6e3a1c9a60151973bbfe264028ab2a Mon Sep 17 00:00:00 2001 From: Allen Porter Date: Sun, 13 Apr 2025 17:42:24 -0700 Subject: [PATCH] Improve local calendar error logging when uploading invalid .ics files (#142891) --- .../components/local_calendar/config_flow.py | 13 ++++++++++--- .../components/local_calendar/strings.json | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/local_calendar/config_flow.py b/homeassistant/components/local_calendar/config_flow.py index fef45f786f9..f5b3220fb8c 100644 --- a/homeassistant/components/local_calendar/config_flow.py +++ b/homeassistant/components/local_calendar/config_flow.py @@ -97,8 +97,7 @@ class LocalCalendarConfigFlow(ConfigFlow, domain=DOMAIN): user_input[CONF_ICS_FILE], self.data[CONF_STORAGE_KEY], ) - except HomeAssistantError as err: - _LOGGER.debug("Error saving uploaded file: %s", err) + except InvalidIcsFile: errors[CONF_ICS_FILE] = "invalid_ics_file" else: return self.async_create_entry( @@ -112,6 +111,10 @@ class LocalCalendarConfigFlow(ConfigFlow, domain=DOMAIN): ) +class InvalidIcsFile(HomeAssistantError): + """Error to indicate that the uploaded file is not a valid ICS file.""" + + def save_uploaded_ics_file( hass: HomeAssistant, uploaded_file_id: str, storage_key: str ): @@ -122,6 +125,10 @@ def save_uploaded_ics_file( try: CalendarStream.from_ics(ics) except CalendarParseError as err: - raise HomeAssistantError("Failed to upload file: Invalid ICS file") from err + _LOGGER.error("Error reading the calendar information: %s", err.message) + _LOGGER.debug( + "Additional calendar error detail: %s", str(err.detailed_error) + ) + raise InvalidIcsFile("Failed to upload file: Invalid ICS file") from err dest_path = Path(hass.config.path(STORAGE_PATH.format(key=storage_key))) shutil.move(file, dest_path) diff --git a/homeassistant/components/local_calendar/strings.json b/homeassistant/components/local_calendar/strings.json index 2b61fc9ab3e..6d68b46b5b0 100644 --- a/homeassistant/components/local_calendar/strings.json +++ b/homeassistant/components/local_calendar/strings.json @@ -17,7 +17,7 @@ "already_configured": "[%key:common::config_flow::abort::already_configured_service%]" }, "error": { - "invalid_ics_file": "Invalid .ics file" + "invalid_ics_file": "There was a problem reading the calendar information. See the error log for additional details." } }, "selector": {