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 3
3
from http import HTTPStatus
4
4
5
5
from mfr .extensions .tabular import utilities
6
- from mfr .extensions .tabular .exceptions import EmptyTableError , TabularRendererError
6
+ from mfr .extensions .tabular .exceptions import (EmptyTableError ,
7
+ TabularRendererError )
7
8
8
9
9
10
def csv_stdlib (fp ):
@@ -73,6 +74,14 @@ def parse_stdlib(reader):
73
74
code = HTTPStatus .BAD_REQUEST ,
74
75
extension = 'csv' ) from e
75
76
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
+
76
85
if not columns and not rows :
77
86
raise EmptyTableError ('Cannot render file as csv/tsv. '
78
87
'The file may be empty or corrupt' ,
Original file line number Diff line number Diff line change 4
4
import pytest
5
5
6
6
from 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 )
9
9
10
10
BASE = os .path .dirname (os .path .abspath (__file__ ))
11
11
@@ -49,3 +49,9 @@ def test_csv_stdlib_exception_raises(self):
49
49
with pytest .raises (EmptyTableError ) as e :
50
50
stdlib_tools .tsv_stdlib (fp )
51
51
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