Skip to content

Commit

Permalink
feat: Add line number to FieldSizeLimitError message, closes #681
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmckinney committed Jul 14, 2021
1 parent c4edc31 commit f235b6a
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Expand Up @@ -4,6 +4,7 @@
* feat: :meth:`.Table.from_json` accepts an ``encoding`` keyword argument. (#734)
* feat: :meth:`.Table.print_html` accepts a ``max_precision`` keyword argument. (#753)
* feat: :class:`.Max` works with :class:`.TimeDelta`. (#735)
* feat: :class:`.FieldSizeLimitError` includes the line number in the error message. (#681)
* fix: :class:`.Mean` returns ``None`` if there are no values to average. (#706)
* fix: :meth:`.Table.homogenize` accepts tuples. (#710)
* fix: Ensure files are closed when errors occur. (#734)
Expand Down
2 changes: 1 addition & 1 deletion agate/csv_py2.py
Expand Up @@ -54,7 +54,7 @@ def next(self):
except csv.Error as e:
# Terrible way to test for this exception, but there is no subclass
if 'field larger than field limit' in str(e):
raise FieldSizeLimitError(csv.field_size_limit())
raise FieldSizeLimitError(csv.field_size_limit(), csv.line_num)
else:
raise e

Expand Down
2 changes: 1 addition & 1 deletion agate/csv_py3.py
Expand Up @@ -35,7 +35,7 @@ def __next__(self):
except csv.Error as e:
# Terrible way to test for this exception, but there is no subclass
if 'field larger than field limit' in str(e):
raise FieldSizeLimitError(csv.field_size_limit())
raise FieldSizeLimitError(csv.field_size_limit(), self.line_num)
else:
raise e

Expand Down
5 changes: 3 additions & 2 deletions agate/exceptions.py
Expand Up @@ -34,7 +34,8 @@ class FieldSizeLimitError(Exception): # pragma: no cover
This length may be the default or one set by the user.
"""
def __init__(self, limit):
def __init__(self, limit, line_number):
super(FieldSizeLimitError, self).__init__(
'CSV contains fields longer than maximum length of %i characters. Try raising the maximum with the field_size_limit parameter, or try setting quoting=csv.QUOTE_NONE.' % limit
'CSV contains a field longer than the maximum length of %i characters on line %i. Try raising the maximum '
'with the field_size_limit parameter, or try setting quoting=csv.QUOTE_NONE.' % (limit, line_number)
)

0 comments on commit f235b6a

Please sign in to comment.