Search code examples
rubyrubocop

syntax error, unexpected keyword_rescue, expecting keyword_end


I have the following ruby code:

  EmailTemplate.for(mailer).each do |template|
    begin
      print '.'
      template.upload(publish)
    rescue Mandrill::UnknownTemplateError
      failed.push(mailer)
    end
  end

Rubocop corrected my code to:

EmailTemplate.for(mailer).each do |template|
    print '.'
    template.upload(publish)
  rescue Mandrill::UnknownTemplateError
    failed.push(mailer)
  end

and now it returns following error:

syntax error, unexpected keyword_rescue, expecting keyword_end

How can I fix that?

Rubocop warnings was:

C: Style/RedundantBegin: Redundant begin block detected.

Solution

  • For some reason, Rubocop thinks you're running Ruby 2.5, not Ruby 2.4.1.

    You can fix this one of two ways:

    1) Create a file .ruby-version with content 2.4.1. Rubocop should pick up your Ruby version from this file.
    2) Add the following to your .rubocop.yml:

    AllCops:
      TargetRubyVersion: 2.4