File tree Expand file tree Collapse file tree 3 files changed +18
-3
lines changed
mfr/extensions/tabular/libs Expand file tree Collapse file tree 3 files changed +18
-3
lines changed Original file line number Diff line number Diff line change 33from http import HTTPStatus
44
55from mfr .extensions .tabular import utilities
6- from mfr .extensions .tabular .exceptions import EmptyTableError , TabularRendererError
6+ from mfr .extensions .tabular .exceptions import (EmptyTableError ,
7+ TabularRendererError )
78
89
910def csv_stdlib (fp ):
@@ -73,6 +74,14 @@ def parse_stdlib(reader):
7374 code = HTTPStatus .BAD_REQUEST ,
7475 extension = 'csv' ) from e
7576
77+ # Outside other except because the `if any` line causes more errors to be raised
78+ # on certain exceptions
79+ except UnicodeDecodeError as e :
80+ raise TabularRendererError ('Cannot render file as csv/tsv. '
81+ 'The file may be empty or corrupt' ,
82+ code = HTTPStatus .BAD_REQUEST ,
83+ extension = 'csv' ) from e
84+
7685 if not columns and not rows :
7786 raise EmptyTableError ('Cannot render file as csv/tsv. '
7887 'The file may be empty or corrupt' ,
Original file line number Diff line number Diff line change 44import pytest
55
66from mfr .extensions .tabular .libs import stdlib_tools
7- from mfr .extensions .tabular .exceptions import EmptyTableError
8-
7+ from mfr .extensions .tabular .exceptions import ( EmptyTableError ,
8+ TabularRendererError )
99
1010BASE = os .path .dirname (os .path .abspath (__file__ ))
1111
@@ -49,3 +49,9 @@ def test_csv_stdlib_exception_raises(self):
4949 with pytest .raises (EmptyTableError ) as e :
5050 stdlib_tools .tsv_stdlib (fp )
5151 assert e .value .code == 400
52+
53+ def test_csv_stdlib_other_exception_raises (self ):
54+ with open (os .path .join (BASE , 'files' , 'invalid_null.csv' )) as fp :
55+ with pytest .raises (TabularRendererError ) as e :
56+ stdlib_tools .tsv_stdlib (fp )
57+ assert e .value .code == 400
You can’t perform that action at this time.
0 commit comments