Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

not reporting rake tasks #25

Closed
choxi opened this issue Feb 15, 2013 · 12 comments
Closed

not reporting rake tasks #25

choxi opened this issue Feb 15, 2013 · 12 comments

Comments

@choxi
Copy link

choxi commented Feb 15, 2013

I'm got this gem setup in my Rails app, but it doesn't seem to catch errors inside of Rake tasks:

task :cron_task => :environment do
  raise "error in cron task"
end

doesn't report anything on Ratchet, but this works:

task :cron_task  => :environment do
  begin
    raise "error in cron task"
  rescue Exception => e
    Ratchetio.report_exception(e)
  end
end

Is this by design? It looks like this gem taps into some Rack middleware to catch exceptions which would explain why it doesn't work for Rake tasks, is there a recommended way to have it catch all my Rake tasks?

@brianr
Copy link
Member

brianr commented Feb 15, 2013

There isn't a recommended way to catch exceptions in all Rake tasks (besides your second example), but it seems like there ought to be something the gem can hook into. Investigating...

@choxi
Copy link
Author

choxi commented Feb 15, 2013

I checked out how Airbrake does it: https://github.com/airbrake/airbrake/blob/master/lib/airbrake/rake_handler.rb

and this worked for me:

# top of my Rakefile

Rake::Application.class_eval do
  def display_error_message_with_ratchet(e)
    Ratchetio.report_exception(e)
    display_error_message_without_ratchet(e)
  end

  alias_method :display_error_message_without_ratchet, :display_error_message
  alias_method :display_error_message, :display_error_message_with_ratchet
end

What do you think?

@brianr
Copy link
Member

brianr commented Feb 15, 2013

Just pushed this to a branch; it's basically the same as what you just posted: https://github.com/ratchetio/ratchetio-gem/compare/capture-rake-exceptions

That work? Is the class_eval approach better?

@choxi
Copy link
Author

choxi commented Feb 17, 2013

Nice! I think the only difference between that and class_eval is stylistic, I like your approach better.

Will this be merged into master at some point?

@brianr
Copy link
Member

brianr commented Feb 17, 2013

Merging now...

@brianr
Copy link
Member

brianr commented Feb 17, 2013

Merged to master and pushed version 0.7.0 to rubygems.

@brianr brianr closed this as completed Feb 17, 2013
@choxi
Copy link
Author

choxi commented Feb 17, 2013

Thanks! :)

@hlascelles
Copy link

Oh heck, this was a breaking change for us - see stack.

A load order issue? I'll look into it further, but downgrading to 0.6.0 fixes it.

[18:42:39][Execute spec] /opt/teamcity-agent/work/6bedf4b37b77680/vendor/ruby/1.9.1/gems/ratchetio-0.7.0/lib/ratchetio/rake.rb:3:in alias_method': undefined methoddisplay_error_message' for class Rake::Application' (NameError) [18:42:39][Execute spec] from /opt/teamcity-agent/work/6bedf4b37b77680/vendor/ruby/1.9.1/gems/ratchetio-0.7.0/lib/ratchetio/rake.rb:3:inclass:Application'
[18:42:39][Execute spec] from /opt/teamcity-agent/work/6bedf4b37b77680/vendor/ruby/1.9.1/gems/ratchetio-0.7.0/lib/ratchetio/rake.rb:2:in <module:Rake>' [18:42:39][Execute spec] from /opt/teamcity-agent/work/6bedf4b37b77680/vendor/ruby/1.9.1/gems/ratchetio-0.7.0/lib/ratchetio/rake.rb:1:in<top (required)>'
[18:42:39][Execute spec] from /opt/teamcity-agent/work/6bedf4b37b77680/vendor/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:251:in require' [18:42:39][Execute spec] from /opt/teamcity-agent/work/6bedf4b37b77680/vendor/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:251:inblock in require'
[18:42:39][Execute spec] from /opt/teamcity-agent/work/6bedf4b37b77680/vendor/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:236:in load_dependency' [18:42:39][Execute spec] from /opt/teamcity-agent/work/6bedf4b37b77680/vendor/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:251:inrequire'
[18:42:39][Execute spec] from /opt/teamcity-agent/work/6bedf4b37b77680/vendor/ruby/1.9.1/gems/ratchetio-0.7.0/lib/ratchetio.rb:18:in <top (required)>' [18:42:39][Execute spec] from /opt/teamcity-agent/work/6bedf4b37b77680/vendor/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:251:inrequire'
[18:42:39][Execute spec] from /opt/teamcity-agent/work/6bedf4b37b77680/vendor/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:251:in block in require' [18:42:39][Execute spec] from /opt/teamcity-agent/work/6bedf4b37b77680/vendor/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:236:inload_dependency'
[18:42:39][Execute spec] from /opt/teamcity-agent/work/6bedf4b37b77680/vendor/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:251:in require' [18:42:39][Execute spec] from /opt/teamcity-agent/work/6bedf4b37b77680/vendor/ruby/1.9.1/gems/ratchetio-0.7.0/lib/ratchetio/rails.rb:1:in<top (required)>'
[18:42:39][Execute spec] from /opt/teamcity-agent/work/6bedf4b37b77680/vendor/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:251:in require' [18:42:39][Execute spec] from /opt/teamcity-agent/work/6bedf4b37b77680/vendor/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:251:inblock in require'
[18:42:39][Execute spec] from /opt/teamcity-agent/work/6bedf4b37b77680/vendor/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:236:in load_dependency' [18:42:39][Execute spec] from /opt/teamcity-agent/work/6bedf4b37b77680/vendor/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:251:inrequire'
[18:42:39][Execute spec] from /opt/teamcity-agent/work/6bedf4b37b77680/vendor/ruby/1.9.1/bundler/gems/banco-rails-base-80630954457e/config/initializers/ratchetio.rb:1:in <top (required)>' [18:42:39][Execute spec] from /opt/teamcity-agent/work/6bedf4b37b77680/vendor/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:245:inload'
[18:42:39][Execute spec] from /opt/teamcity-agent/work/6bedf4b37b77680/vendor/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:245:in block in load' [18:42:39][Execute spec] from /opt/teamcity-agent/work/6bedf4b37b77680/vendor/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:236:inload_dependency'
[18:42:39][Execute spec] from /opt/teamcity-agent/work/6bedf4b37b77680/vendor/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:245:in load' [18:42:39][Execute spec] from /opt/teamcity-agent/work/6bedf4b37b77680/vendor/ruby/1.9.1/gems/railties-3.2.12/lib/rails/engine.rb:588:inblock (2 levels) in class:Engine'
[18:42:39][Execute spec] from /opt/teamcity-agent/work/6bedf4b37b77680/vendor/ruby/1.9.1/gems/railties-3.2.12/lib/rails/engine.rb:587:in each' [18:42:39][Execute spec] from /opt/teamcity-agent/work/6bedf4b37b77680/vendor/ruby/1.9.1/gems/railties-3.2.12/lib/rails/engine.rb:587:inblock in class:Engine'
[18:42:39][Execute spec] from /opt/teamcity-agent/work/6bedf4b37b77680/vendor/ruby/1.9.1/gems/railties-3.2.12/lib/rails/initializable.rb:30:in instance_exec' [18:42:39][Execute spec] from /opt/teamcity-agent/work/6bedf4b37b77680/vendor/ruby/1.9.1/gems/railties-3.2.12/lib/rails/initializable.rb:30:inrun'
[18:42:39][Execute spec] from /opt/teamcity-agent/work/6bedf4b37b77680/vendor/ruby/1.9.1/gems/railties-3.2.12/lib/rails/initializable.rb:55:in block in run_initializers' [18:42:39][Execute spec] from /opt/teamcity-agent/work/6bedf4b37b77680/vendor/ruby/1.9.1/gems/railties-3.2.12/lib/rails/initializable.rb:54:ineach'
[18:42:39][Execute spec] from /opt/teamcity-agent/work/6bedf4b37b77680/vendor/ruby/1.9.1/gems/railties-3.2.12/lib/rails/initializable.rb:54:in run_initializers' [18:42:39][Execute spec] from /opt/teamcity-agent/work/6bedf4b37b77680/vendor/ruby/1.9.1/gems/railties-3.2.12/lib/rails/application.rb:136:ininitialize!'
[18:42:39][Execute spec] from /opt/teamcity-agent/work/6bedf4b37b77680/vendor/ruby/1.9.1/gems/railties-3.2.12/lib/rails/railtie/configurable.rb:30:in `method_missing'

@brianr
Copy link
Member

brianr commented Feb 19, 2013

That's no good :( thanks for the report. Will look into this later today.

@bradx3
Copy link
Contributor

bradx3 commented Mar 14, 2013

I'm still seeing the problem @hlascelles reported - is it fixed? Should I open a different github issue for the problem?

@brianr
Copy link
Member

brianr commented Mar 14, 2013

@bradx3 are you on at least 0.8.2? If so, please do open a new github issue. @hlascelles figured out a fix for his setup, which made it into 0.8.2. Quoting from our email exchange, that fix was:

I can recreated every time, and have a solution.

In our spec tests, rake has not actually (yet) been used (ie rspec from the command line), so that class Rake::Application doesn't exist (yet).

The simple fix is to

require 'rake'

At the top of your gem's rake.rb file.

@hlascelles
Copy link

Yes, the new rollbar gem (with that require included) fixed it for me. Alternatively, you can put

require 'rake'

at the top of your spec_helper.rb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants