taichino / croniter

croniter is a python module to provide iteration for datetime object.
http://github.com/taichino/croniter
387 stars 105 forks source link

When validating cron expression, croniter can throw non-Croniter exceptions #155

Closed cuu508 closed 3 years ago

cuu508 commented 3 years ago

A test sample:

from datetime import datetime

from croniter import croniter

it = croniter("0-1& * * * *", datetime.now())

Running this throws a ValueError, not any of the CroniterError subclasses. What is the intended behavior? Would returning anything other than CroniterError count as bug?

From a consumer perspective, when handling user-submitted cron expressions, it would be nice to be able to wrap croniter calls in try ... except CroniterError. Currently, for the sake of safety, I catch all exceptions:

try: 
    ... initialize croniter, iterate over datetimes ...
except:
    ... assume the user-submitted cron expression is not valid ...
kiorky commented 3 years ago

I will try to shallow this in a CroniterBadExpression

kiorky commented 3 years ago

1.0.3 is out !