From dfc257ef22ff860ad21d0f719c8b212386482d04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Fri, 15 Oct 2021 11:13:04 +0300 Subject: [PATCH] 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. --- hc/front/views.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/hc/front/views.py b/hc/front/views.py index f9793d51..019b1227 100644 --- a/hc/front/views.py +++ b/hc/front/views.py @@ -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"]: