Skip to content

Instantly share code, notes, and snippets.

@xunker
Created January 27, 2012 23:36
Show Gist options
  • Save xunker/1691595 to your computer and use it in GitHub Desktop.
Save xunker/1691595 to your computer and use it in GitHub Desktop.
skip csv lines with errors
tmpfile = Tempfile.new('csv_file_with_errors')
FasterCSV.open(tmpfile.path, "r", :headers => true) do |output|
loop do
begin
break unless row = output.shift
next unless row.field_row?
# do your thing here
rescue FasterCSV::MalformedCSVError => e
# report the error
next
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment