Permalink
Browse files

Make map_fields recoverable from FasterCSV::MalformedCSVError

  • Loading branch information...
1 parent 502d116 commit e371483fac42b85932d6d188e50c65d93c41c54e @bjeanes committed Jun 22, 2009
Showing with 11 additions and 5 deletions.
  1. +11 −5 lib/map_fields.rb
View
16 lib/map_fields.rb
@@ -31,12 +31,18 @@ def map_fields
end
session[:map_fields][:file] = temp_path
-
- @rows = []
- FasterCSV.foreach(temp_path) do |row|
- @rows << row
- break if @rows.size == 10
+
+ begin
+ @rows = []
+ FasterCSV.foreach(temp_path) do |row|
+ @rows << row
+ break if @rows.size == 10
+ end
+ rescue FasterCSV::MalformedCSVError => e
+ @map_fields_error = e
+ return
end
+
expected_fields = self.class.read_inheritable_attribute(:map_fields_fields)
@fields = ([nil] + expected_fields).inject([]){ |o, e| o << [e, o.size]}
@parameters = []

0 comments on commit e371483

Please sign in to comment.