Browse Source

Update hc.front.views.cron_preview to catch CronSimError explicitly

With a catch-all "except:" rule, we would swallow any unexpected
exceptions (ValueError, etc.) in cronsim. But we want to know
about them. cron_preview is a place where we can afford to crash, and generate a crash report.
master
Pēteris Caune 3 years ago
parent
commit
dfc257ef22
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
1 changed files with 2 additions and 5 deletions
  1. +2
    -5
      hc/front/views.py

+ 2
- 5
hc/front/views.py View File

@ -7,7 +7,7 @@ from secrets import token_urlsafe
from urllib.parse import urlencode
from cron_descriptor import ExpressionDescriptor
from cronsim import CronSim
from cronsim.cronsim import CronSim, CronSimError
from django.conf import settings
from django.contrib import messages
from django.contrib.auth.decorators import login_required
@ -496,16 +496,13 @@ def cron_preview(request):
zone = pytz.timezone(tz)
now_local = timezone.localtime(timezone.now(), zone)
if len(schedule.split()) != 5:
raise ValueError()
it = CronSim(schedule, now_local)
for i in range(0, 6):
ctx["dates"].append(next(it))
except UnknownTimeZoneError:
ctx["bad_tz"] = True
except:
except CronSimError:
ctx["bad_schedule"] = True
if ctx["dates"]:


Loading…
Cancel
Save