commit c7d7d90c0b8ca4c3ec6dffead669f0706854e2fc
parent 8a5d124de57db5cf3e1a28cfbefd74fa9dabbcdb
Author: Carlosokumu <carlosokumu254@gmail.com>
Date: Tue, 2 Sep 2025 21:39:52 +0300
add check attempting edits for invalid ical files
Diffstat:
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/ungana/cmd/args_parser.py b/ungana/cmd/args_parser.py
@@ -254,8 +254,12 @@ class ArgsParser:
updates, attachments = self._get_user_updates_from_args(args)
if any([updates, attachments]):
# Non-interactive mode
- ICalHelper.update_event(cal, updates, attachments, ical_file_path)
- logging.info("Calendar updated successfully")
+ try:
+ ICalHelper.update_event(cal, updates, attachments, ical_file_path)
+ logging.info("Calendar updated successfully")
+ except Exception as e:
+ self.parser.error(f"Failed to update calendar: {e}")
+ return
else:
# Interactive mode
self._edit_most_recent_event(cal, args, ical_file_path)
diff --git a/ungana/ical/ical_helper.py b/ungana/ical/ical_helper.py
@@ -8,6 +8,13 @@ class ICalHelper:
@staticmethod
def update_event(cal: Calendar, updates: Dict[str, Any], attachments: list = None, filename: str = None) -> Calendar:
+ if cal is None or not hasattr(cal, "walk"):
+ raise ValueError("Invalid calendar object: missing structure or corrupted.")
+
+ events = [c for c in cal.walk("VEVENT")]
+ if not events:
+ raise ValueError("Calendar does not contain any VEVENT entries.")
+
uid = cal.walk("VEVENT")[0].get("UID")
event_found = False