diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/csv.rb | 9 | ||||
| -rw-r--r-- | lib/csv/parser.rb | 6 |
2 files changed, 11 insertions, 4 deletions
diff --git a/lib/csv.rb b/lib/csv.rb index d4dc569b83..81fa99aa99 100644 --- a/lib/csv.rb +++ b/lib/csv.rb @@ -854,6 +854,15 @@ class CSV end end + # The error thrown when the parser encounters invalid encoding in CSV. + class InvalidEncodingError < MalformedCSVError + attr_reader :encoding + def initialize(encoding, line_number) + @encoding = encoding + super("Invalid byte sequence in #{encoding}", line_number) + end + end + # # A FieldInfo Struct contains details about a field's position in the data # source it was read from. CSV will pass this Struct to some blocks that make diff --git a/lib/csv/parser.rb b/lib/csv/parser.rb index ed9297fe30..4da87fbac8 100644 --- a/lib/csv/parser.rb +++ b/lib/csv/parser.rb @@ -414,8 +414,7 @@ class CSV else lineno = @lineno + 1 end - message = "Invalid byte sequence in #{@encoding}" - raise MalformedCSVError.new(message, lineno) + raise InvalidEncodingError.new(@encoding, lineno) rescue UnexpectedError => error if @scanner ignore_broken_line @@ -876,8 +875,7 @@ class CSV !line.valid_encoding? end if index - message = "Invalid byte sequence in #{@encoding}" - raise MalformedCSVError.new(message, @lineno + index + 1) + raise InvalidEncodingError.new(@encoding, @lineno + index + 1) end end Scanner.new(string) |
