From fbd019711c927bd9d2e4840e9d4d8af596e12cb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ebbinghaus?= Date: Mon, 7 Oct 2024 10:30:47 +0200 Subject: [PATCH] Degrading an annoying error into a warning (#438) Solves https://github.com/python-caldav/caldav/issues/426 Also changes multiple log lines into a multi-line log message --- caldav/lib/vcal.py | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/caldav/lib/vcal.py b/caldav/lib/vcal.py index e196f4c..a87d28b 100644 --- a/caldav/lib/vcal.py +++ b/caldav/lib/vcal.py @@ -89,32 +89,29 @@ def fix(event): if fixed2 != event: global fixup_error_loggings fixup_error_loggings += 1 - remove_bit = lambda n: n & (n - 1) - if not remove_bit(fixup_error_loggings): - log = logging.error + is_power_of_two = lambda n: not (n & (n - 1)) + if is_power_of_two(fixup_error_loggings): + log = logging.warning else: log = logging.debug - log( - """Ical data was modified to avoid compatibility issues -(Your calendar server breaks the icalendar standard) -This is probably harmless, particularly if not editing events or tasks -(error count: %i - this error is ratelimited)""" - % fixup_error_loggings, - exc_info=True, - ) + + log_message = [ + "Ical data was modified to avoid compatibility issues", + "(Your calendar server breaks the icalendar standard)", + "This is probably harmless, particularly if not editing events or tasks", + f"(error count: {fixup_error_loggings} - this error is ratelimited)", + ] + try: import difflib - log( - "\n".join( - difflib.unified_diff( - event.split("\n"), fixed2.split("\n"), lineterm="" - ) - ) + diff = list( + difflib.unified_diff(event.split("\n"), fixed2.split("\n"), lineterm="") ) except: - log("Original: \n" + event) - log("Modified: \n" + fixed2) + diff = ["Original: ", event, "Modified: ", fixed2] + + log("\n".join(log_message + diff)) return fixed2