mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 22:27:07 +00:00
Improve local calendar error logging when uploading invalid .ics files (#142891)
This commit is contained in:
parent
d91528648f
commit
5b8ca8d0ed
@ -97,8 +97,7 @@ class LocalCalendarConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
user_input[CONF_ICS_FILE],
|
user_input[CONF_ICS_FILE],
|
||||||
self.data[CONF_STORAGE_KEY],
|
self.data[CONF_STORAGE_KEY],
|
||||||
)
|
)
|
||||||
except HomeAssistantError as err:
|
except InvalidIcsFile:
|
||||||
_LOGGER.debug("Error saving uploaded file: %s", err)
|
|
||||||
errors[CONF_ICS_FILE] = "invalid_ics_file"
|
errors[CONF_ICS_FILE] = "invalid_ics_file"
|
||||||
else:
|
else:
|
||||||
return self.async_create_entry(
|
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(
|
def save_uploaded_ics_file(
|
||||||
hass: HomeAssistant, uploaded_file_id: str, storage_key: str
|
hass: HomeAssistant, uploaded_file_id: str, storage_key: str
|
||||||
):
|
):
|
||||||
@ -122,6 +125,10 @@ def save_uploaded_ics_file(
|
|||||||
try:
|
try:
|
||||||
CalendarStream.from_ics(ics)
|
CalendarStream.from_ics(ics)
|
||||||
except CalendarParseError as err:
|
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)))
|
dest_path = Path(hass.config.path(STORAGE_PATH.format(key=storage_key)))
|
||||||
shutil.move(file, dest_path)
|
shutil.move(file, dest_path)
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
"already_configured": "[%key:common::config_flow::abort::already_configured_service%]"
|
"already_configured": "[%key:common::config_flow::abort::already_configured_service%]"
|
||||||
},
|
},
|
||||||
"error": {
|
"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": {
|
"selector": {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user