Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError (class or module required for rescue clause)

Tags:

ruby

ruby-2.1

I've been using Stripe for over a year now, based on Ryan Bates's RailsCast episode found here. However, my error handling has recently stopped working, and I've never seen this error before. I recently began running my app on Ruby 2.1, and as near as I can tell, that's the problem.

This is an instance method in my Subscription model:

    begin
      save_with_stripe_payment
    rescue Stripe::InvalidRequestError => e
      logger.error "Stripe error while creating customer: #{e.message}"
      logger.error e.backtrace.join("\n")
      errors.add :base, "There was a problem with your card."
      false
    rescue e
      logger.error e.message
      logger.error e.backtrace.join("\n")
      errors.add :base, e.message
      false
    end

The line:

    rescue Stripe::InvalidRequestError => e

is the one throwing the error. The stacktrace from there goes to the "begin" line, and that's it. What am I missing here?

like image 353
AKWF Avatar asked Oct 31 '14 19:10

AKWF


2 Answers

The line number in the error is a little misleading, the error is actually coming from this:

rescue e

I think you meant

rescue => e
like image 124
Max Avatar answered Nov 01 '22 01:11

Max


I got this error because I was trying to rescue an array of exceptions, e.g.

rescue *exceptions => e

except that exceptions was an instance of an exception (my mistake).

like image 29
localhostdotdev Avatar answered Nov 01 '22 01:11

localhostdotdev