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

Unnecessary airbrake error when running unknown rake task #13

Closed
khustochka opened this issue Dec 24, 2015 · 11 comments · Fixed by #14
Closed

Unnecessary airbrake error when running unknown rake task #13

khustochka opened this issue Dec 24, 2015 · 11 comments · Fixed by #14
Labels

Comments

@khustochka
Copy link

  • Airbrake version: 5.0.1
  • Ruby version: 2.2.3
  • Framework name & version: Rails 4.2.5

Airbrake config

  Airbrake.configure do |config|
    config.project_id = <project_id>
    config.project_key = <project_key>
    config.host = <host>
    config.ignore_environments = [:test]
  end

Description

I checked that my config is OK by running rake airbrake:test, it runs successfully.

But when I run a rake task that does not exist I am getting the following output:

$ bin/rake kokoko:dskfkl
rake aborted!
Don't know how to build task 'kokoko:dskfkl'

(See full trace by running task with --trace)
/Users/vkhustochka/.rvm/gems/ruby-2.2.3@quails/gems/airbrake-ruby-1.0.1/lib/airbrake-ruby.rb:282:in `call_notifier': the 'default' notifier isn't configured (Airbrake::Error)
    from /Users/vkhustochka/.rvm/gems/ruby-2.2.3@quails/gems/airbrake-ruby-1.0.1/lib/airbrake-ruby.rb:149:in `notify_sync'
    from /Users/vkhustochka/.rvm/gems/ruby-2.2.3@quails/gems/airbrake-ruby-1.0.1/lib/airbrake-ruby.rb:291:in `block in <top (required)>'

I think the issue is that in this case airbrake is loaded (through bundler) but initializers are not loaded, so Airbrake config is not loaded.

@khustochka
Copy link
Author

The same also happens for any rake task (even if it was successful) if Airbrake is not configured.

@kyrylo kyrylo added the Bug label Dec 25, 2015
kyrylo added a commit that referenced this issue Dec 25, 2015
Fixes #13 (Unnecessary airbrake error when running unknown rake task)

The problem with Rake is that on unknown task it
[raises SystemExit][1] with help of [`Kernel.exit`][2], which we catch
and try to send to Airbrake, which results in an Airbrake::Error.

This is the easiest fix. I tried messing with the airbrake gem to load
the Airbrake config when you launch a Rake task inside a Rails app, but
it's not easy to do: the Rails app is not initialised at that moment.

I stopped digging there, because I was getting into the rabbit hole.

[1]: https://github.com/ruby/rake/blob/805c13ab52eae9df55f9030f40c7fbc1beadc105/lib/rake/application.rb#L191
[2]: http://ruby-doc.org/core-2.2.3/Kernel.html#method-i-exit
kyrylo added a commit that referenced this issue Dec 25, 2015
Fixes #13 (Unnecessary airbrake error when running unknown rake task)

The problem with Rake is that on unknown task it
[raises SystemExit][1] with help of [`Kernel.exit`][2], which we catch
and try to send to Airbrake, which results in an Airbrake::Error.

This is the easiest fix. I tried messing with the airbrake gem to load
the Airbrake config when you launch a Rake task inside a Rails app, but
it's not easy to do: the Rails app is not initialised at that moment.

I stopped digging there, because I was getting into the rabbit hole.

[1]: https://github.com/ruby/rake/blob/805c13ab52eae9df55f9030f40c7fbc1beadc105/lib/rake/application.rb#L191
[2]: http://ruby-doc.org/core-2.2.3/Kernel.html#method-i-exit
@kyrylo
Copy link
Contributor

kyrylo commented Dec 25, 2015

Thanks for the bug report. Could you please verify that the fix presented in #14 works for you?

Merry Christmas! =)

@vmihailenco
Copy link

The same also happens for any rake task (even if it was successful) if Airbrake is not configured.

Do you mean that Airbrake is always not configured?

@khustochka
Copy link
Author

@vmihailenco I think I meant it fails for rake tasks that do not load rails environment.

@khustochka
Copy link
Author

@kyrylo Yes, it fixes the problem. Thank you.

@kyrylo kyrylo closed this as completed in #14 Jan 2, 2016
@rafaelgonzalez
Copy link

  • Airbrake version: 5.0.2
  • Airbrake-ruby version: 1.0.2
  • Ruby version: 2.2.3
  • Framework name & version: Rails 4.2.5

Airbrake config

Airbrake.configure do |config|
  config.project_id = 'foo'
  config.project_key = 'bar'

  config.ignore_environments = %w(development test)
end

Description

Hello, I am having a very similar error to this. It happens when RSpec's rake task exits because of a failing spec.

I'm using the latest version (1.0.2) and I'm not quite sure why #14 does not apply in this case, as it seems to be SystemExit as well.

I removed some irrelevant output from RSpec, but the output I get is this:

$ RAILS_ENV=test rake spec

--Snip--

Finished in 4.02 seconds (files took 2.22 seconds to load)
97 examples, 1 failure

Failed examples:

--Snip--

Randomized with seed 50266

/Users/rafaelgonzalez/.rvm/rubies/ruby-2.2.3/bin/ruby -I/Users/rafaelgonzalez/.rvm/gems/ruby-2.2.3/gems/rspec-core-3.4.1/lib:/Users/rafaelgonzalez/.rvm/gems/ruby-2.2.3/gems/rspec-support-3.4.1/lib /Users/rafaelgonzalez/.rvm/gems/ruby-2.2.3/gems/rspec-core-3.4.1/exe/rspec --pattern spec/\*\*\{,/\*/\*\*\}/\*_spec.rb failed
rake aborted!
Airbrake::Error: the 'default' notifier isn't configured
/Users/rafaelgonzalez/.rvm/gems/ruby-2.2.3/gems/airbrake-ruby-1.0.2/lib/airbrake-ruby.rb:282:in `call_notifier'
/Users/rafaelgonzalez/.rvm/gems/ruby-2.2.3/gems/airbrake-ruby-1.0.2/lib/airbrake-ruby.rb:236:in `build_notice'
/Users/rafaelgonzalez/.rvm/gems/ruby-2.2.3/gems/airbrake-5.0.2/lib/airbrake/rake/task_ext.rb:21:in `rescue in execute'
/Users/rafaelgonzalez/.rvm/gems/ruby-2.2.3/gems/airbrake-5.0.2/lib/airbrake/rake/task_ext.rb:19:in `execute'
SystemExit: exit
/Users/rafaelgonzalez/.rvm/gems/ruby-2.2.3/gems/rspec-core-3.4.1/lib/rspec/core/rake_task.rb:84:in `exit'
/Users/rafaelgonzalez/.rvm/gems/ruby-2.2.3/gems/rspec-core-3.4.1/lib/rspec/core/rake_task.rb:84:in `run_task'
/Users/rafaelgonzalez/.rvm/gems/ruby-2.2.3/gems/rspec-core-3.4.1/lib/rspec/core/rake_task.rb:96:in `block (2 levels) in define'
/Users/rafaelgonzalez/.rvm/gems/ruby-2.2.3/gems/rspec-core-3.4.1/lib/rspec/core/rake_task.rb:94:in `block in define'
/Users/rafaelgonzalez/.rvm/gems/ruby-2.2.3/gems/airbrake-5.0.2/lib/airbrake/rake/task_ext.rb:19:in `execute'
Tasks: TOP => spec
(See full trace by running task with --trace)

Let me know if you would prefer a separate issue for this, I'm posting here since the issue seems fairly similar.

@kyrylo
Copy link
Contributor

kyrylo commented Jan 13, 2016

@rafaelgonzalez what happens when you configure your Airbrake inside spec_helper.rb (simply copy-paste the config)?

@kyrylo
Copy link
Contributor

kyrylo commented Jan 13, 2016

Do you get the same results with:

  • rake spec (without the env specifier)
  • bundle exec rake

@davidrf
Copy link

davidrf commented Jan 14, 2016

@kyrylo @rafaelgonzalez I had the same problem of having that stack trace show up when the tests failed when invoking rake. Placing my Airbrake inside spec_helper.rb gave me 'configure': the 'default' notifier was already configured (Airbrake::Error). Also, running the tests with rspec did not raise the stack trace. I actually managed to get the stack trace to go away by placing the following at the bottom of my Rakefile.

Airbrake.configure do |config|
  config.project_key = ''
  config.project_id = ''
end

However, now I cannot run any other rake tasks....So I am just living with it for the moment.

@kyrylo
Copy link
Contributor

kyrylo commented Jan 14, 2016

Please file an issue. This seems to be a different problem.

@rafaelgonzalez
Copy link

@kyrylo, I have answered your questions below, but as per your request have also opened #28 to move the discussion there.

@rafaelgonzalez what happens when you configure your Airbrake inside spec_helper.rb (simply copy-paste the config)?

If I add the airbrake config to my spec_helper.rb like so:

require 'simplecov'
SimpleCov.start 'rails'

require 'factory_girl_rails'
require 'airbrake'

RSpec.configure do |config|
  config.expect_with :rspec do |expectations|
    expectations.include_chain_clauses_in_custom_matcher_descriptions = true
  end

  config.mock_with :rspec do |mocks|
    mocks.verify_partial_doubles = true
  end

  config.filter_run :focus
  config.run_all_when_everything_filtered = true

  config.disable_monkey_patching!

  if config.files_to_run.one?
    config.default_formatter = 'doc'
  end

  config.order = :random

  Kernel.srand config.seed

  config.include FactoryGirl::Syntax::Methods
end

Airbrake.configure do |config|
  config.project_id = 'foo'
  config.project_key = 'bar'

  config.environment = Rails.env # I added this since my previous post, but removing it does not affect this issue
  config.ignore_environments = %w(development test)
end

Sorry for the verbosity, I just want to give you as much context as possible.

Do you get the same results with:

  • rake spec (without the env specifier)
  • bundle exec rake
  • rake spec does not output anything for me when not specifying the environment, that is, it does not run the specs at all, and exits without doing anything. (I suspect this is because RSpec is under the :test group in my Gemfile)
  • bundle exec rspec does not trigger the error when specs fail.
  • bundle exec rake does trigger the error when specs fail (this is how I came across this issue in the first place)

kyrylo added a commit that referenced this issue Jan 18, 2016
Fixes #28 ("Airbrake::Error: the 'default' notifier isn't configured"
thrown after unsuccessful specs)

This fixes issues with the Rake integration. There was a [similar
issue][1] reported a couple of weeks ago. The change presented here
fixes both issues by reraising `SystemExit`, which propagates it and
gets handled by Ruby.

[1]: #13
kyrylo added a commit that referenced this issue Jan 18, 2016
Fixes #28 ("Airbrake::Error: the 'default' notifier isn't configured"
thrown after unsuccessful specs)

This fixes issues with the Rake integration. There was a [similar
issue][1] to a bug with the Rake integration reported a couple of weeks
ago. The change presented here fixes both issues by reraising
`SystemExit`, which propagates it and gets handled by Ruby.

[1]: #13
kyrylo added a commit that referenced this issue Jan 18, 2016
Fixes #28 ("Airbrake::Error: the 'default' notifier isn't configured"
thrown after unsuccessful specs)

This fixes issues with the Rake integration. There was a [similar
issue][1] to a bug with the Rake integration reported a couple of weeks
ago. The change presented here fixes both issues by reraising
`SystemExit`, which propagates it and gets handled by Ruby.

[1]: #13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants