Skip to content
Browse files

Don't ever rescue Exception. It catches signals.

  • Loading branch information...
1 parent a9e6a2a commit 4671a6159efd67fc78d8dd267bb6e8da3655c379 @samg samg committed Dec 16, 2011
View
8 lib/new_relic/agent/agent.rb
@@ -129,9 +129,9 @@ def record_transaction(duration_seconds, options={})
if options['exception']
e = options['exception']
elsif options['error_message']
- e = Exception.new options['error_message']
+ e = StandardError.new options['error_message']
else
- e = Exception.new 'Unknown Error'
+ e = StandardError.new 'Unknown Error'
end
error_collector.notice_error e, :uri => options['uri'], :metric => metric
end
@@ -538,7 +538,7 @@ def catch_errors
handle_force_disconnect(e)
rescue NewRelic::Agent::ServerConnectionException => e
handle_server_connection_problem(e)
- rescue Exception => e
+ rescue => e
handle_other_error(e)
end
@@ -1281,7 +1281,7 @@ def save_or_transmit_data
log.debug "Serializing agent data to disk"
NewRelic::Agent.save_data
end
- rescue Exception => e
+ rescue => e
NewRelic::Control.instance.disable_serialization = true
NewRelic::Control.instance.log.warn("Disabling serialization: #{e.message}")
retry_count ||= 0
View
4 lib/new_relic/agent/database.rb
@@ -95,12 +95,12 @@ def process_resultset(items)
def handle_exception_in_explain
yield
- rescue Exception => e
+ rescue => e
begin
# guarantees no throw from explain_sql
NewRelic::Control.instance.log.error("Error getting query plan: #{e.message}")
NewRelic::Control.instance.log.debug(e.backtrace.join("\n"))
- rescue Exception
+ rescue
# double exception. throw up your hands
end
end
View
2 lib/new_relic/agent/error_collector.rb
@@ -223,7 +223,7 @@ def notice_error(exception, options={})
exception_options = error_params_from_options(options).merge(exception_info(exception))
add_to_error_queue(NewRelic::NoticedError.new(action_path, exception_options, exception))
exception
- rescue Exception => e
+ rescue => e
log.error("Error capturing an error, yodawg. #{e}")
end
View
4 lib/new_relic/agent/instrumentation/controller_instrumentation.rb
@@ -256,7 +256,7 @@ def perform_action_with_newrelic_trace(*args, &block)
else
perform_action_without_newrelic_trace(*args)
end
- rescue Exception => e
+ rescue => e
frame_data.notice_error(e)
raise
end
@@ -425,7 +425,7 @@ def _detect_upstream_wait(now)
queue_start = parse_frontend_headers(newrelic_request_headers)
end
queue_start || now
- rescue Exception => e
+ rescue => e
NewRelic::Control.instance.log.error("Error detecting upstream wait time: #{e}")
NewRelic::Control.instance.log.debug("#{e.backtrace[0..20]}")
now
View
2 lib/new_relic/agent/instrumentation/metric_frame.rb
@@ -67,7 +67,7 @@ def self.agent
include_class 'java.lang.management.ManagementFactory'
include_class 'com.sun.management.OperatingSystemMXBean'
@@java_classes_loaded = true
- rescue Exception => e
+ rescue => e
end
end
View
2 lib/new_relic/agent/stats_engine/samplers.rb
@@ -74,7 +74,7 @@ def poll(samplers)
begin
sampled_item.poll
false # it's okay. don't delete it.
- rescue Exception => e
+ rescue => e
log.error "Removing #{sampled_item} from list"
log.error e
log.debug e.backtrace.to_s
View
2 lib/new_relic/agent/worker_loop.rb
@@ -74,7 +74,7 @@ def run_task
# Want to ignore these because they are handled already
rescue SystemExit, NoMemoryError, SignalException
raise
- rescue Exception => e
+ rescue => e
# Don't blow out the stack for anything that hasn't already propagated
log.error "Error running task in Agent Worker Loop '#{e}': #{e.backtrace.first}"
log.debug e.backtrace.join("\n")
View
2 lib/new_relic/commands/deployments.rb
@@ -72,7 +72,7 @@ def run
raise NewRelic::Command::CommandFailure.new(err_string)
rescue NewRelic::Command::CommandFailure
raise
- rescue Exception => e
+ rescue => e
err "Unexpected error attempting to connect to #{config.api_server}"
info "#{e}: #{e.backtrace.join("\n ")}"
raise NewRelic::Command::CommandFailure.new(e.to_s)
View
2 lib/new_relic/control/frameworks/merb.rb
@@ -13,7 +13,7 @@ def root
def to_stdout(msg)
Merb.logger.info("NewRelic ~ " + msg)
- rescue Exception => e
+ rescue => e
STDOUT.puts "NewRelic ~ " + msg
end
View
8 lib/new_relic/control/frameworks/rails.rb
@@ -57,7 +57,7 @@ def install_browser_monitoring(config)
require 'new_relic/rack/browser_monitoring'
config.middleware.use NewRelic::Rack::BrowserMonitoring
log!("Installed New Relic Browser Monitoring middleware", :info)
- rescue Exception => e
+ rescue => e
log!("Error installing New Relic Browser Monitoring middleware: #{e.inspect}", :error)
end
end
@@ -77,7 +77,7 @@ def install_developer_mode(rails_config)
log!("NewRelic Agent Developer Mode enabled.")
log!("To view performance information, go to http://localhost#{port}/newrelic")
end
- rescue Exception => e
+ rescue => e
log!("Error installing New Relic Developer Mode: #{e.inspect}", :error)
end
elsif rails_config
@@ -92,14 +92,14 @@ def log!(msg, level=:info)
else
super
end
- rescue Exception => e
+ rescue => e
super
end
def to_stdout(message)
logger = ::Rails.respond_to?(:logger) ? ::Rails.logger : ::RAILS_DEFAULT_LOGGER
logger.info(message)
- rescue Exception => e
+ rescue => e
super
end
View
2 lib/new_relic/control/frameworks/rails3.rb
@@ -37,7 +37,7 @@ def log!(msg, level=:info)
else
super
end
- rescue Exception => e
+ rescue => e
super
end
View
2 lib/new_relic/control/instrumentation.rb
@@ -17,7 +17,7 @@ def load_instrumentation_files pattern
begin
log.debug "Processing instrumentation file '#{file}'"
require file.to_s
- rescue Exception => e
+ rescue => e
log.error "Error loading instrumentation file '#{file}': #{e}"
log.debug e.backtrace.join("\n")
end
View
4 lib/new_relic/control/server_methods.rb
@@ -63,13 +63,13 @@ def convert_to_ip_address(host)
# address and don't have a good default.
def resolve_ip_address(host)
Resolv.getaddress(host)
- rescue Exception => e
+ rescue => e
log.warn("DNS Error caching IP address: #{e}")
log.debug(e.backtrace.join("\n "))
begin
log.info("Trying native DNS lookup since Resolv failed")
IPSocket.getaddress(host)
- rescue Exception => e
+ rescue => e
log.error("Could not look up server address: #{e}")
nil
end
View
4 lib/new_relic/data_serialization.rb
@@ -16,7 +16,7 @@ def should_send_data?
NewRelic::Control.instance.disable_serialization? || store_too_large? ||
store_too_old? || pid_too_old? ||
NewRelic::LanguageSupport.using_version?('1.8.6')
- rescue Exception => e
+ rescue => e
NewRelic::Control.instance.disable_serialization = true
NewRelic::Control.instance.log.warn("Disabling serialization: #{e.message}")
true
@@ -81,7 +81,7 @@ def with_locked_store
f.flock(File::LOCK_UN)
end
end
- rescue Exception => e
+ rescue => e
NewRelic::Control.instance.log.error("Error serializing data to disk: #{e.inspect}")
NewRelic::Control.instance.log.debug(e.backtrace.split("\n"))
# re-raise so that serialization will be disabled higher up the stack
View
6 lib/new_relic/local_environment.rb
@@ -49,7 +49,7 @@ def initialize
def append_environment_value(name, value = nil)
value = yield if block_given?
@config[name] = value if value
- rescue Exception
+ rescue
# puts "#{e}\n #{e.backtrace.join("\n ")}"
raise if @framework == :test
end
@@ -58,7 +58,7 @@ def append_environment_value(name, value = nil)
# of gems - this catches errors that might be raised in the block
def append_gem_list
@gems += yield
- rescue Exception => e
+ rescue => e
# puts "#{e}\n #{e.backtrace.join("\n ")}"
raise if @framework == :test
end
@@ -67,7 +67,7 @@ def append_gem_list
# of plugins - this catches errors that might be raised in the block
def append_plugin_list
@plugins += yield
- rescue Exception
+ rescue
# puts "#{e}\n #{e.backtrace.join("\n ")}"
raise if @framework == :test
end
View
2 lib/new_relic/recipes.rb
@@ -50,7 +50,7 @@
logger.info e.message
rescue Capistrano::CommandError
logger.info "Unable to notify New Relic of the deployment... skipping"
- rescue Exception => e
+ rescue => e
logger.info "Error creating New Relic deployment (#{e})\n#{e.backtrace.join("\n")}"
end
# WIP: For rollbacks, let's update the deployment we created with an indication of the failure:
View
6 test/active_record_fixtures.rb
@@ -12,7 +12,7 @@ def teardown
ActiveRecordFixtures::Order.teardown
begin
super
- rescue Exception => e
+ rescue => e
end
end
class Order < ActiveRecord::Base
@@ -30,7 +30,7 @@ def self.setup
def self.check_for_table
connection.table_exists?(self.table_name)
- rescue Exception => e
+ rescue => e
false
end
@@ -66,7 +66,7 @@ def self.setup
end
def self.check_for_table
connection.table_exists?(self.table_name) && connection.table_exists?('orders_shipments')
- rescue Exception => e
+ rescue => e
false
end
View
2 test/new_relic/agent/database_test.rb
@@ -74,7 +74,7 @@ def test_explain_sql_one_select_no_connection
end
def test_handle_exception_in_explain
- fake_error = Exception.new('a message')
+ fake_error = StandardError.new('a message')
NewRelic::Control.instance.log.expects(:error).with('Error getting query plan: a message')
# backtrace can be basically any string, just should get logged
NewRelic::Control.instance.log.expects(:debug).with(instance_of(String))
View
30 test/new_relic/agent/error_collector_test.rb
@@ -29,7 +29,7 @@ def test_empty
end
def test_simple
- @error_collector.notice_error(Exception.new("message"), :uri => '/myurl/', :metric => 'path', :referer => 'test_referer', :request_params => {:x => 'y'})
+ @error_collector.notice_error(StandardError.new("message"), :uri => '/myurl/', :metric => 'path', :referer => 'test_referer', :request_params => {:x => 'y'})
old_errors = []
errors = @error_collector.harvest_errors(old_errors)
@@ -42,7 +42,7 @@ def test_simple
assert err.params[:request_uri] == '/myurl/'
assert err.params[:request_referer] == "test_referer"
assert err.path == 'path'
- assert err.exception_class == 'Exception'
+ assert err.exception_class == 'StandardError'
# the collector should now return an empty array since nothing
# has been added since its last harvest
@@ -53,7 +53,7 @@ def test_simple
def test_long_message
#yes, times 500. it's a 5000 byte string. Assuming strings are
#still 1 byte / char.
- @error_collector.notice_error(Exception.new("1234567890" * 500), :uri => '/myurl/', :metric => 'path', :request_params => {:x => 'y'})
+ @error_collector.notice_error(StandardError.new("1234567890" * 500), :uri => '/myurl/', :metric => 'path', :request_params => {:x => 'y'})
old_errors = []
errors = @error_collector.harvest_errors(old_errors)
@@ -66,22 +66,22 @@ def test_long_message
end
def test_collect_failover
- @error_collector.notice_error(Exception.new("message"), :metric => 'first', :request_params => {:x => 'y'})
+ @error_collector.notice_error(StandardError.new("message"), :metric => 'first', :request_params => {:x => 'y'})
errors = @error_collector.harvest_errors([])
- @error_collector.notice_error(Exception.new("message"), :metric => 'second', :request_params => {:x => 'y'})
- @error_collector.notice_error(Exception.new("message"), :metric => 'path', :request_params => {:x => 'y'})
- @error_collector.notice_error(Exception.new("message"), :metric => 'last', :request_params => {:x => 'y'})
+ @error_collector.notice_error(StandardError.new("message"), :metric => 'second', :request_params => {:x => 'y'})
+ @error_collector.notice_error(StandardError.new("message"), :metric => 'path', :request_params => {:x => 'y'})
+ @error_collector.notice_error(StandardError.new("message"), :metric => 'last', :request_params => {:x => 'y'})
errors = @error_collector.harvest_errors(errors)
assert_equal 4, errors.length
assert_equal 'first', errors.first.path
assert_equal 'last', errors.last.path
- @error_collector.notice_error(Exception.new("message"), :metric => 'first', :request_params => {:x => 'y'})
- @error_collector.notice_error(Exception.new("message"), :metric => 'last', :request_params => {:x => 'y'})
+ @error_collector.notice_error(StandardError.new("message"), :metric => 'first', :request_params => {:x => 'y'})
+ @error_collector.notice_error(StandardError.new("message"), :metric => 'last', :request_params => {:x => 'y'})
errors = @error_collector.harvest_errors(nil)
assert_equal 2, errors.length
@@ -95,7 +95,7 @@ def test_queue_overflow
silence_stream(::STDOUT) do
(max_q_length + 5).times do |n|
- @error_collector.notice_error(Exception.new("exception #{n}"), :metric => "path", :request_params => {:x => n})
+ @error_collector.notice_error(StandardError.new("exception #{n}"), :metric => "path", :request_params => {:x => n})
end
end
@@ -120,13 +120,13 @@ def test_supported_param_types
[1.1, '1.1'],
['hi', 'hi'],
[:hi, :hi],
- [Exception.new("test"), "#<Exception>"],
+ [StandardError.new("test"), "#<StandardError>"],
[TestClass.new, "#<NewRelic::Agent::ErrorCollectorTest::TestClass>"]
]
types.each do |test|
- @error_collector.notice_error(Exception.new("message"), :metric => 'path', :request_params => {:x => test[0]})
+ @error_collector.notice_error(StandardError.new("message"), :metric => 'path', :request_params => {:x => test[0]})
assert_equal test[1], @error_collector.harvest_errors([])[0].params[:request_params][:x]
end
@@ -148,7 +148,7 @@ def test_exclude_block
@error_collector.ignore_error_filter &wrapped_filter_proc
@error_collector.notice_error(IOError.new("message"), :metric => 'path', :request_params => {:x => 'y'})
- @error_collector.notice_error(Exception.new("message"), :metric => 'path', :request_params => {:x => 'y'})
+ @error_collector.notice_error(StandardError.new("message"), :metric => 'path', :request_params => {:x => 'y'})
errors = @error_collector.harvest_errors([])
@@ -158,8 +158,8 @@ def test_exclude_block
def test_obfuscates_error_messages_when_high_security_is_set
NewRelic::Control.instance['high_security'] = true
- @error_collector.notice_error(Exception.new("YO SQL BAD: serect * flom test where foo = 'bar'"))
- @error_collector.notice_error(Exception.new("YO SQL BAD: serect * flom test where foo in (1,2,3,4,5)"))
+ @error_collector.notice_error(StandardError.new("YO SQL BAD: serect * flom test where foo = 'bar'"))
+ @error_collector.notice_error(StandardError.new("YO SQL BAD: serect * flom test where foo in (1,2,3,4,5)"))
old_errors = []
errors = @error_collector.harvest_errors([])
View
2 test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb
@@ -10,7 +10,7 @@ def setup
ActiveRecordFixtures.setup
NewRelic::Agent.instance.transaction_sampler.reset!
NewRelic::Agent.instance.stats_engine.clear_stats
- rescue Exception => e
+ rescue => e
puts e
puts e.backtrace.join("\n")
end
View
4 test/new_relic/agent/method_tracer_test.rb
@@ -309,11 +309,11 @@ def test_exception
metric = "hey"
self.class.trace_execution_scoped metric do
assert @stats_engine.peek_scope.name == metric
- throw Exception.new
+ throw StandardError.new
end
assert false # should never get here
- rescue Exception
+ rescue StandardError
# make sure the scope gets popped
assert @stats_engine.peek_scope == nil
end
View
2 test/new_relic/agent/transaction_sample_builder_test.rb
@@ -42,7 +42,7 @@ def test_freeze
begin
builder.sample
assert false
- rescue Exception => e
+ rescue => e
# expected
end
View
2 test/new_relic/agent/worker_loop_test.rb
@@ -45,7 +45,7 @@ def test_task_error__standard
end
assert done
end
- class BadBoy < Exception; end
+ class BadBoy < StandardError; end
def test_task_error__exception
@logger.expects(:error).once

0 comments on commit 4671a61

Please sign in to comment.
Something went wrong with that request. Please try again.