Capturing errors on way out

I would like to be able to publish to SNS topic(s) on exceptions.

Is there a way to capture all exceptions on the way out of the controller…is there something like the rescue_from I’ve read briefly about or can I accomplish something similar with an after_action

As always, thanks for the patience…not a ruby guy so I could very well be asking stoopid questions…that said, any help would be greatly appreciated.

This will help :grin: How do I report exceptions to a service like Sentry or Honeybadger?

To add more clarity. So there’s no rescue_from currently.

Currently, you have to create a Turbine. Turbines are one way to extend Jets. Here’s an example (untested):

lib/my_turbine.rb:

class MyTurbine < ::Jets::Turbine
    on_exception 'my_turbine.capture' do |exception|
      # my exception handing code
    end
end

config/initializers/my_turbine.rb:

require_relative "lib/my_turbine.rb"

Note, this handles all exceptions: controllers, jobs, etc. Will have to look into adding something like a rescue_from in time as it’s easier than creating a Turbine.

No worries…there is a way so I’m good. Thanks. I’ll play with Turbine

I must be doing something wrong…I’ve tried both sentry-jets and honeybadger-jets with no luck…
I then tried the MyTurbine example above and in none of the cases do I ever seem to land in on_exception. initializer happens as expected but not on_exception . I’ve attempted raise and throw but have been unsuccessful.

I’ve done no other initialization other creating config/initializers/my_turbine.rb . Is there a step I am missing?

~bb

@balutbomber

RE: Is there a step I am missing?

Don’t think you’re missing steps.

Realized that the on_exception hook only fires remotely on AWS Lambda, not locally. Update docs to help clarify http://rubyonjets.com/docs/jets-turbines/

To reproduce the on_exception hook firing locally you can run it through what jets uses to process the function on AWS Lambda: Jets.process

Here’s an example project https://github.com/tongueroo/jets-turbine-example . The HardJob#dig method raises an intentional error. Here’s the reproduction in jets console

$ bundle exec jets console
required my_turbine.rb
Jets booting up in development mode!
>> Jets.process({},{}, "handlers/jobs/hard_job.dig")
done digging
RubyError: RuntimeError: the roof
...
my exception handling code
Traceback (most recent call last):
       16: from /home/ec2-user/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/jets-1.7.1/lib/jets/cli.rb:5:in `start'
       15: from /home/ec2-user/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/jets-1.7.1/lib/jets/cli.rb:21:in `start'
       14: from /home/ec2-user/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/jets-1.7.1/lib/jets/commands/base.rb:27:in `perform'
...
        3: from app/jobs/hard_job.rb:1:in `run'
        2: from /home/ec2-user/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/jets-1.7.1/lib/jets/job/base.rb:15:in `process'
        1: from /home/ec2-user/environment/demo/app/jobs/hard_job.rb:7:in `dig'
RuntimeError (the roof)
>> 
$ 

Full trace: https://gist.github.com/tongueroo/202e4a15de6cc990fd8bb66c12042075

Also, ran into a small bug where Turbines would fail if they did not have an initializer block. That’s been fixed in v1.7.1

Hope that helps.

As always, thanks for the quick response…I’m back up and running. Sorry, I didn’t try to capture in a deployed environment before posting…that said, having a way to play with it locally is always a good thing.

~bb