Created
May 3, 2011 06:12
-
-
Save tsujigiri/952883 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def parse filename, content | |
offset = 0 | |
begin | |
FasterCSV.parse(content) do |row| | |
# do stuff | |
offset += row.to_s.size | |
end | |
rescue FasterCSV::MalformedCSVError => e | |
@file_offset ||= 0 | |
@file_offset += offset | |
# cut offset chars from the beginning of content | |
malformed_row, content = content.split("\n", 2) | |
e.set_backtrace [ "#{filename}:#{@file_offset} #{malformed_row}" ] | |
@file_offset += malformed_row.size + 1 | |
parse filename, content if content.present? | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment