From 35b8c04f6a1261d0641f3f19a999030ffbfe8e65 Mon Sep 17 00:00:00 2001 From: Peter Havekes Date: Fri, 19 Oct 2018 11:40:23 +0200 Subject: Catch some errors in _calendar_addics. --- calendar-cli.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/calendar-cli.py b/calendar-cli.py index d3c444f..4bfc8bf 100755 --- a/calendar-cli.py +++ b/calendar-cli.py @@ -139,11 +139,21 @@ def _calendar_addics(caldav_conn, ics, uid, args): raise ValueError("Nothing to do/invalid option combination for 'calendar add'-mode; either both --icalendar and --nocaldav should be set, or none of them") return - c = find_calendar(caldav_conn, args) - if re.search(r'^METHOD:[A-Z]+[\r\n]+',ics,flags=re.MULTILINE) and args.ignoremethod: - ics = re.sub(r'^METHOD:[A-Z]+[\r\n]+', '', ics, flags=re.MULTILINE) - print ("METHOD property found and ignored") - c.add_event(ics) + try: + c = find_calendar(caldav_conn, args) + if re.search(r'^METHOD:[A-Z]+[\r\n]+',ics,flags=re.MULTILINE) and args.ignoremethod: + ics = re.sub(r'^METHOD:[A-Z]+[\r\n]+', '', ics, flags=re.MULTILINE) + print ("METHOD property found and ignored") + c.add_event(ics) + except caldav.lib.error.AuthorizationError as e: + print("Error logging in"); + sys.exit(2) + except caldav.lib.error.PutError as e: + if "200 OK" in str(e): + print("Duplicate") + else: + raise e + def calendar_addics(caldav_conn, args): """ -- cgit v1.2.3