diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 83943adf..d0089636 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -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) diff --git a/agate/csv_py2.py b/agate/csv_py2.py index 32a113b5..546aa5dd 100644 --- a/agate/csv_py2.py +++ b/agate/csv_py2.py @@ -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 diff --git a/agate/csv_py3.py b/agate/csv_py3.py index 918af60a..e7183182 100644 --- a/agate/csv_py3.py +++ b/agate/csv_py3.py @@ -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 diff --git a/agate/exceptions.py b/agate/exceptions.py index 7fbfcc29..0673c7c4 100644 --- a/agate/exceptions.py +++ b/agate/exceptions.py @@ -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) )