Skip to content

Instantly share code, notes, and snippets.

@tsujigiri
Created May 3, 2011 06:12
Show Gist options
  • Save tsujigiri/952883 to your computer and use it in GitHub Desktop.
Save tsujigiri/952883 to your computer and use it in GitHub Desktop.
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