niccokunzmann / python-recurring-ical-events

Python library to calculate recurrence times of events, todos and journals based on icalendar RFC5545
https://pypi.org/project/recurring-ical-events/
GNU Lesser General Public License v3.0
94 stars 22 forks source link

bug: Series.__init__ raise errors on bad events even if skip_bad_series is true #172

Closed fabien-michel closed 1 month ago

fabien-michel commented 1 month ago

In Series.__init__, there are 2 exceptions raised : here and here

It seems that these errors are linked to a malformed event. In that case they should be skiped/quiet if skip_bad_series is true.

I suggest, to make specific exceptions for these two cases and default make them skipable.

class NoComponentEvent(InvalidCalendar):
    """An event has no component"""

class OnlyModificationsEvent(InvalidCalendar):
    """A component only contains modifications"""

    def __init__(self, message: str, uid: str):
        """Create an error with component uid."""
        super().__init__(message + ": " + uid)
        self._uid = uid

    @property
    def uid(self) -> str:
        """The uid of the component"""
        return self._uid
...
raise NoComponentEvent("No components given to calculate a series.")
...
raise OnlyModificationsEvent(
    f"The event definition for {components[0].uid} "
    "only contains modifications.",
    components[0].uid,
)
...

suppressed_errors = [
        BadRuleStringFormat,
        PeriodEndBeforeStart,
        OnlyModificationsEvent,
        NoComponentEvent,
]

...


We're using Polar.sh so you can upvote and help fund this issue. We receive the funding once the issue is completed & confirmed by you. Thank you in advance for helping prioritize & fund our work.

Fund with Polar

niccokunzmann commented 1 month ago

This sounds like a lovely suggestion! Indeed we would want those to be skipped. At the same time: If we have an event series and it does not have a 'core' event but only recurrences specified, we could assume that these recurrences should be part of the results. That is probably another issue but also related if the error messages are removed due to that. What are your thoughts as a default on this? It would not be a 'skip bad events' rather we would incorporate those into the event series. I will check your other issue...

niccokunzmann commented 1 month ago

In some way, for this specific error, I would say that this is a duplicate of #173.

niccokunzmann commented 1 month ago

Please check with v3.3.0 if this can be closed.

gpkvt commented 1 month ago

At least for my usecase 3.3.0 fixed this issue. Thanks!

fabien-michel commented 1 month ago

Thanks, all our calendars previously crashing on it, now pass !