Data-Liberation-Front / csvlint.rb

The gem behind http://csvlint.io
MIT License
283 stars 86 forks source link

undefined method `present?' for nil:NilClass #229

Closed tit closed 3 years ago

tit commented 4 years ago

Hi, I try test csvlint from CLI. But csvlint return error: undefined methodpresent?' for nil:NilClass (NoMethodError)`. Why?

$ cat main.csv 
foo,bar
1,2

$ csvlint main.csv 
Traceback (most recent call last):
    17: from /Users/tit/.rvm/gems/ruby-2.5.1/bin/ruby_executable_hooks:24:in `<main>'
    16: from /Users/tit/.rvm/gems/ruby-2.5.1/bin/ruby_executable_hooks:24:in `eval'
    15: from /Users/tit/.rvm/gems/ruby-2.5.1/bin/csvlint:23:in `<main>'
    14: from /Users/tit/.rvm/gems/ruby-2.5.1/bin/csvlint:23:in `load'
    13: from /Users/tit/.rvm/gems/ruby-2.5.1/gems/csvlint-0.4.0/bin/csvlint:9:in `<top (required)>'
    12: from /Users/tit/.rvm/gems/ruby-2.5.1/gems/thor-0.20.3/lib/thor/base.rb:466:in `start'
    11: from /Users/tit/.rvm/gems/ruby-2.5.1/gems/thor-0.20.3/lib/thor.rb:387:in `dispatch'
    10: from /Users/tit/.rvm/gems/ruby-2.5.1/gems/thor-0.20.3/lib/thor/invocation.rb:126:in `invoke_command'
     9: from /Users/tit/.rvm/gems/ruby-2.5.1/gems/thor-0.20.3/lib/thor/command.rb:27:in `run'
     8: from /Users/tit/.rvm/gems/ruby-2.5.1/gems/csvlint-0.4.0/lib/csvlint/cli.rb:24:in `validate'
     7: from /Users/tit/.rvm/gems/ruby-2.5.1/gems/csvlint-0.4.0/lib/csvlint/cli.rb:141:in `validate_csv'
     6: from /Users/tit/.rvm/gems/ruby-2.5.1/gems/csvlint-0.4.0/lib/csvlint/cli.rb:141:in `new'
     5: from /Users/tit/.rvm/gems/ruby-2.5.1/gems/csvlint-0.4.0/lib/csvlint/validate.rb:86:in `initialize'
     4: from /Users/tit/.rvm/gems/ruby-2.5.1/gems/csvlint-0.4.0/lib/csvlint/validate.rb:101:in `validate'
     3: from /Users/tit/.rvm/gems/ruby-2.5.1/gems/csvlint-0.4.0/lib/csvlint/validate.rb:108:in `validate_stream'
     2: from /Users/tit/.rvm/gems/ruby-2.5.1/gems/csvlint-0.4.0/lib/csvlint/validate.rb:108:in `each_line'
     1: from /Users/tit/.rvm/gems/ruby-2.5.1/gems/csvlint-0.4.0/lib/csvlint/validate.rb:109:in `block in validate_stream'
/Users/tit/.rvm/gems/ruby-2.5.1/gems/csvlint-0.4.0/lib/csvlint/validate.rb:553:in `line_limit_reached?': undefined method `present?' for nil:NilClass (NoMethodError)
igelstorm commented 4 years ago

I'm getting this error too when trying to run the CLI tool.

I think present? is not a core Ruby method, but comes from Rails (ActiveSupport) – could this be a Rails dependency that's not been declared, but hasn't caused problems elsewhere because the main use case for this gem is within a Rails app (csvlint.io) where the method would be available?

igelstorm commented 4 years ago

Update: This error occurs when using Ruby 2.6, but not when using Ruby 2.4. The simplest fix for a user is to switch to Ruby 2.4 or 2.5 when using this gem. For anyone who just needs a CLI tool to validate a CSV with a table schema (which is what I needed) and isn't specifically tied to Ruby, there's also goodtables.

It seems that this gem doesn't support Ruby 2.6, and this is now reflected in the gemspec, but the latest release available from Rubygems (0.4.0) doesn't explicitly have this requirement, so there's nothing stopping a user running 2.6 from installing it.

It might be helpful to release a new version, or at least mention in the README which Ruby versions are supported?

Floppy commented 4 years ago

Good spot, thanks. We do need to get a new version released now that we're trying to get it back into a maintained state. I'll see if we can do that soon.