From 602fb2d9cd97451eb858973bb34e9104918e58ee Mon Sep 17 00:00:00 2001 From: neingeist Date: Mon, 12 Nov 2018 14:36:19 +0100 Subject: [PATCH] handle file error using an exception --- prolefeeder.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/prolefeeder.py b/prolefeeder.py index 8236767..45245b1 100644 --- a/prolefeeder.py +++ b/prolefeeder.py @@ -34,12 +34,12 @@ def download(): form.start_time.data = datetime.now().replace(minute=0, second=0) - timedelta(hours=1) form.length.data = 60 elif form.validate_on_submit(): - output_filename = prepare_download(form) - if output_filename: + try: + output_filename = prepare_download(form) flash('The download should start immediately.', 'success') return render_template('download.html', form=form, filename=output_filename) - else: - flash('Error preparing download!', 'warning') + except ValueError as e: + flash('Error preparing download: {}'.format(e), 'warning') else: flash('Error in form!', 'warning') return render_template('download.html', form=form) @@ -79,7 +79,7 @@ def prepare_download(form): if source['start_time'] <= form.start_time.data < source['start_time'] + source['length']: start_index = i if start_index is None: - return None + raise ValueError('Could not find start file') sources = sources[start_index:] # Seek into the first file