rubyruby-2.1

TypeError (class or module required for rescue clause)


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?


Solution

  • 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