Skip to content

Commit

Permalink
Degrading an annoying error into a warning (#438)
Browse files Browse the repository at this point in the history
Solves #426

Also changes multiple log lines into a multi-line log message
  • Loading branch information
MrEbbinghaus authored Oct 7, 2024
1 parent 4c38183 commit fbd0197
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions caldav/lib/vcal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit fbd0197

Please sign in to comment.