Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NoMethodError occurred at #gets after MalformedCSVError #82

Closed
krororo opened this issue Mar 20, 2019 · 3 comments
Closed

NoMethodError occurred at #gets after MalformedCSVError #82

krororo opened this issue Mar 20, 2019 · 3 comments

Comments

@krororo
Copy link

krororo commented Mar 20, 2019

reproduction code:

require 'csv'

puts CSV::VERSION
csv = CSV.new(<<~CSV, headers: true, return_headers: true)
  head1,head2,head3
  aaa,bbb,ccc
  ddd,ee"e.fff
  ggg,hhh,iii
CSV

until csv.eof?
  begin
    p csv.gets
  rescue CSV::MalformedCSVError => e
    p e
  end
end

ruby 2.6.2:

$ ruby -v && ruby /tmp/csv.rb
ruby 2.6.2p47 (2019-03-13 revision 67232) [x86_64-linux]
3.0.4
#<CSV::Row "head1":"head1" "head2":"head2" "head3":"head3">
#<CSV::Row "head1":"aaa" "head2":"bbb" "head3":"ccc">
#<CSV::MalformedCSVError: Illegal quoting in line 3.>
Traceback (most recent call last):
	3: from /tmp/csv.rb:1:in `each'
	2: from /home/krororo/.rbenv/versions/2.6.2/lib/ruby/2.6.0/csv/parser.rb:236:in `parse'
	1: from /home/krororo/.rbenv/versions/2.6.2/lib/ruby/2.6.0/csv/parser.rb:236:in `new'
/home/krororo/.rbenv/versions/2.6.2/lib/ruby/2.6.0/csv/row.rb:35:in `initialize': undefined method `size' for nil:NilClass (NoMethodError)

ruby 2.5.3:

$ ruby -v && ruby /tmp/csv.rb
ruby 2.5.3p105 (2018-10-18 revision 65156) [x86_64-linux]
2.4.8
#<CSV::Row "head1":"head1" "head2":"head2" "head3":"head3">
#<CSV::Row "head1":"aaa" "head2":"bbb" "head3":"ccc">
#<CSV::MalformedCSVError: Illegal quoting in line 3.>
#<CSV::Row "head1":"ggg" "head2":"hhh" "head3":"iii">

The expected behavior is to get data after an error occurs.

@kou kou closed this as completed in f31fb3b Mar 21, 2019
@kou
Copy link
Member

kou commented Mar 21, 2019

Thanks for your report.
I've fixed it.

BTW, the following backtrace is strange. It may be a CRuby bug. Could you report this to https://bugs.ruby-lang.org/projects/ruby-trunk/issues/new ?

	3: from /tmp/csv.rb:1:in `each'

@krororo
Copy link
Author

krororo commented Mar 21, 2019

@kou
Copy link
Member

kou commented Mar 21, 2019

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants