From c184187e5928078bb7f0837cfe27b9098386e7da Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Tue, 8 Nov 2022 10:27:31 +0100 Subject: [PATCH] Improve error handling for CSV parsing in voucher bulk creation --- src/pretix/control/forms/vouchers.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/pretix/control/forms/vouchers.py b/src/pretix/control/forms/vouchers.py index b4c98b1c36..44162609c4 100644 --- a/src/pretix/control/forms/vouchers.py +++ b/src/pretix/control/forms/vouchers.py @@ -345,8 +345,11 @@ class VoucherBulkForm(VoucherForm): if ',' in raw or ';' in raw: if '@' in r[0]: raise ValidationError(_('CSV input needs to contain a header row in the first line.')) - dialect = csv.Sniffer().sniff(raw[:1024]) - reader = csv.DictReader(StringIO(raw), dialect=dialect) + try: + dialect = csv.Sniffer().sniff(raw[:1024]) + reader = csv.DictReader(StringIO(raw), dialect=dialect) + except csv.Error as e: + raise ValidationError(_('CSV parsing failed: {error}.').format(error=str(e))) if 'email' not in reader.fieldnames: raise ValidationError(_('CSV input needs to contain a field with the header "{header}".').format(header="email")) unknown_fields = [f for f in reader.fieldnames if f not in ('email', 'name', 'tag', 'number')]