Skip to content

Commit

Permalink
Merge pull request #87 from MindscapeHQ/fix-init-error
Browse files Browse the repository at this point in the history
Fix raygun4ruby crashing and suppressing app errors if API key is not configured
  • Loading branch information
UberMouse authored Mar 8, 2017
2 parents dbc5e1e + c24e36d commit 4e4aceb
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@
Features:
- Added two new configuration options, `filter_payload_with_whitelist` and `whitelist_payload_shape`
- See [README.md](https://github.com/MindscapeHQ/raygun4ruby#filtering-the-payload-by-whitelist) for an example of how to use them

Bugfixes:
- raygun4ruby will no longer crash and suppress app exceptions when the API key is not configured
8 changes: 8 additions & 0 deletions lib/raygun.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ def default_configuration
configuration.defaults
end

def configured?
!!configuration.api_key
end

def track_exception(exception_instance, env = {})
if should_report?(exception_instance)
log("[Raygun] Tracking Exception...")
Expand Down Expand Up @@ -71,6 +75,10 @@ def failsafe_log(message)

private

def print_api_key_warning
$stderr.puts(NO_API_KEY_MESSAGE)
end

def should_report?(exception)
return false if configuration.silence_reporting
return false if configuration.ignore.flatten.include?(exception.class.to_s)
Expand Down
4 changes: 2 additions & 2 deletions lib/raygun/middleware/rack_exception_interceptor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ def initialize(app)
def call(env)
response = @app.call(env)
rescue Exception => exception
Raygun.track_exception(exception, env)
Raygun.track_exception(exception, env) if Raygun.configured?
raise exception
end

end
end
end
end
3 changes: 1 addition & 2 deletions lib/raygun/middleware/rails_insert_affected_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ def call(env)

env["raygun.affected_user"] = { :identifier => identifier }
end

end
raise exception
end

end
end
end
end
2 changes: 0 additions & 2 deletions lib/raygun/railtie.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class Raygun::Railtie < Rails::Railtie

initializer "raygun.configure_rails_initialization" do |app|

# Thanks Airbrake: See https://github.com/rails/rails/pull/8624
Expand Down Expand Up @@ -34,5 +33,4 @@ class Raygun::Railtie < Rails::Railtie
rake_tasks do
load "tasks/raygun.tasks"
end

end
12 changes: 12 additions & 0 deletions test/unit/raygun_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# -*- coding: utf-8 -*-
require_relative "../test_helper.rb"
require 'stringio'

class RaygunTest < Raygun::UnitTest

def test_raygun_is_not_configured_with_no_api_key
Raygun.configuration.api_key = nil
assert !Raygun.configured?
end

end

0 comments on commit 4e4aceb

Please sign in to comment.