0

I'm facing this issue while using 'smarter_csv' gem in a ruby CLI script using version 2.4.1. The gem is installed successfully but upon using, I get error:

/Users/macbook/.rvm/rubies/ruby-2.4.1/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:54:in `require': /Users/macbook/.rvm/gems/ruby-2.4.1/gems/smarter_csv-1.7.4/lib/smarter_csv.rb:549: syntax error, unexpected keyword_rescue, expecting keyword_end (SyntaxError)
      rescue EOFError # short files
            ^
/Users/macbook/.rvm/gems/ruby-2.4.1/gems/smarter_csv-1.7.4/lib/smarter_csv.rb:558: syntax error, unexpected keyword_end, expecting end-of-input
        from /Users/macbook/.rvm/rubies/ruby-2.4.1/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:54:in `require'
        from csv_analysis_script.rb:16:in '<main>'

The current version of gem is 1.7.4 I tried installing previous versions of the gem e.g, 1.7.3 & 1.7.1. Moreover, I also uninstalled my ruby version along with gems & reinstalled everything. But nothing works.

Stefan
  • 109,145
  • 14
  • 143
  • 218
  • You are using a very old version of Ruby that was released more than 6 years ago and which support ended more than two years ago. The gem you try to use is not tested against that old version of Ruby anymore. I suggest using an up-to-date version of Ruby. Or you might need to install a version of that gem that was released when Ruby 2.4 was still maintained, which means you might need to downgrade to smart_csv to 1.1.5 or 1.2.0 – spickermann Feb 10 '23 at 07:08
  • 6
    Starting with Ruby 2.5, `rescue` is allowed directly in `do`/`end` blocks (see [release notes](https://www.ruby-lang.org/en/news/2017/12/25/ruby-2-5-0-released/)) which is what happens in [smarter_csv.rb:549](https://github.com/tilo/smarter_csv/blob/v1.7.4/lib/smarter_csv.rb#L549). Ruby versions prior to 2.5 (e.g. your 2.4) will raise a syntax error when encountering such "stray" `rescue`. Upgrading Ruby to 2.5 or above should fix the problem. – Stefan Feb 10 '23 at 08:15
  • Thanks. But unfortunately I couldn't switch the ruby version. So, I went ahead using CSV class. – Mubarra Naz Feb 11 '23 at 13:35

0 Answers0