From 2b5e521f147131be3c3ea00b65f6b2de9bd32e07 Mon Sep 17 00:00:00 2001 From: Justin Collins Date: Wed, 22 Jan 2014 00:29:38 -0800 Subject: [PATCH] Remove `rescue Exception` instances closes #428 --- lib/brakeman/checks.rb | 4 ++-- lib/brakeman/processors/alias_processor.rb | 2 +- .../processors/erb_template_processor.rb | 2 +- .../processors/haml_template_processor.rb | 4 ++-- lib/brakeman/processors/output_processor.rb | 2 +- lib/brakeman/processors/template_processor.rb | 2 +- lib/brakeman/scanner.rb | 16 ++++++++-------- lib/ruby_parser/bm_sexp_processor.rb | 2 +- 8 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/brakeman/checks.rb b/lib/brakeman/checks.rb index 2ead86a8..9bda6176 100644 --- a/lib/brakeman/checks.rb +++ b/lib/brakeman/checks.rb @@ -100,7 +100,7 @@ class Brakeman::Checks begin check.run_check - rescue Exception => e + rescue => e tracker.error e end @@ -138,7 +138,7 @@ class Brakeman::Checks begin check.run_check - rescue Exception => e + rescue => e error_mutex.synchronize do tracker.error e end diff --git a/lib/brakeman/processors/alias_processor.rb b/lib/brakeman/processors/alias_processor.rb index 87989338..975b84d9 100644 --- a/lib/brakeman/processors/alias_processor.rb +++ b/lib/brakeman/processors/alias_processor.rb @@ -58,7 +58,7 @@ class Brakeman::AliasProcessor < Brakeman::SexpProcessor e end end - rescue Exception => err + rescue => err @tracker.error err if @tracker end diff --git a/lib/brakeman/processors/erb_template_processor.rb b/lib/brakeman/processors/erb_template_processor.rb index cf1ce00b..a5afb94e 100644 --- a/lib/brakeman/processors/erb_template_processor.rb +++ b/lib/brakeman/processors/erb_template_processor.rb @@ -20,7 +20,7 @@ class Brakeman::ErbTemplateProcessor < Brakeman::TemplateProcessor @inside_concat = false if exp.second_arg - raise Exception.new("Did not expect more than a single argument to _erbout.concat") + raise "Did not expect more than a single argument to _erbout.concat" end arg = exp.first_arg diff --git a/lib/brakeman/processors/haml_template_processor.rb b/lib/brakeman/processors/haml_template_processor.rb index 9bd31bf9..2b19b0ae 100644 --- a/lib/brakeman/processors/haml_template_processor.rb +++ b/lib/brakeman/processors/haml_template_processor.rb @@ -30,7 +30,7 @@ class Brakeman::HamlTemplateProcessor < Brakeman::TemplateProcessor out = exp.first_arg = process(arg) @inside_concat = false else - raise Exception.new("Empty _hamlout.#{method}()?") + raise "Empty _hamlout.#{method}()?" end if string? out @@ -46,7 +46,7 @@ class Brakeman::HamlTemplateProcessor < Brakeman::TemplateProcessor Sexp.new :format, out end else - raise Exception.new("Unrecognized action on _hamlout: #{method}") + raise "Unrecognized action on _hamlout: #{method}" end end diff --git a/lib/brakeman/processors/output_processor.rb b/lib/brakeman/processors/output_processor.rb index fa94b3fc..afb6c3d0 100644 --- a/lib/brakeman/processors/output_processor.rb +++ b/lib/brakeman/processors/output_processor.rb @@ -18,7 +18,7 @@ class Brakeman::OutputProcessor < Ruby2Ruby def process exp begin super exp if sexp? exp and not exp.empty? - rescue Exception => e + rescue => e Brakeman.debug "While formatting #{exp}: #{e}\n#{e.backtrace.join("\n")}" end end diff --git a/lib/brakeman/processors/template_processor.rb b/lib/brakeman/processors/template_processor.rb index 18d35490..8abbdbcd 100644 --- a/lib/brakeman/processors/template_processor.rb +++ b/lib/brakeman/processors/template_processor.rb @@ -26,7 +26,7 @@ class Brakeman::TemplateProcessor < Brakeman::BaseProcessor def process exp begin super - rescue Exception => e + rescue => e except = e.exception("Error when processing #{@current_template[:name]}: #{e.message}") except.set_backtrace(e.backtrace) raise except diff --git a/lib/brakeman/scanner.rb b/lib/brakeman/scanner.rb index 0816df43..13121dda 100644 --- a/lib/brakeman/scanner.rb +++ b/lib/brakeman/scanner.rb @@ -95,7 +95,7 @@ class Brakeman::Scanner @processor.process_config(parse_ruby(@app_tree.read(path))) end - rescue Exception => e + rescue => e Brakeman.notify "[Notice] Error while processing #{path}" tracker.error e.exception(e.message + "\nwhile processing #{path}"), e.backtrace end @@ -111,7 +111,7 @@ class Brakeman::Scanner @processor.process_gems(parse_ruby(@app_tree.read("Gemfile"))) end end - rescue Exception => e + rescue => e Brakeman.notify "[Notice] Error while processing Gemfile." tracker.error e.exception(e.message + "\nWhile processing Gemfile"), e.backtrace end @@ -131,7 +131,7 @@ class Brakeman::Scanner @processor.process_initializer(path, parse_ruby(@app_tree.read_path(path))) rescue Racc::ParseError => e tracker.error e, "could not parse #{path}. There is probably a typo in the file. Test it with 'ruby_parse #{path}'" - rescue Exception => e + rescue => e tracker.error e.exception(e.message + "\nWhile processing #{path}"), e.backtrace end end @@ -162,7 +162,7 @@ class Brakeman::Scanner @processor.process_lib parse_ruby(@app_tree.read_path(path)), path rescue Racc::ParseError => e tracker.error e, "could not parse #{path}. There is probably a typo in the file. Test it with 'ruby_parse #{path}'" - rescue Exception => e + rescue => e tracker.error e.exception(e.message + "\nWhile processing #{path}"), e.backtrace end end @@ -174,7 +174,7 @@ class Brakeman::Scanner if @app_tree.exists?("config/routes.rb") begin @processor.process_routes parse_ruby(@app_tree.read("config/routes.rb")) - rescue Exception => e + rescue => e tracker.error e.exception(e.message + "\nWhile processing routes.rb"), e.backtrace Brakeman.notify "[Notice] Error while processing routes - assuming all public controller methods are actions." options[:assume_all_routes] = true @@ -219,7 +219,7 @@ class Brakeman::Scanner @processor.process_controller(parse_ruby(@app_tree.read_path(path)), path) rescue Racc::ParseError => e tracker.error e, "could not parse #{path}. There is probably a typo in the file. Test it with 'ruby_parse #{path}'" - rescue Exception => e + rescue => e tracker.error e.exception(e.message + "\nWhile processing #{path}"), e.backtrace end end @@ -305,7 +305,7 @@ class Brakeman::Scanner tracker.error e, "could not parse #{path}" rescue Haml::Error => e tracker.error e, ["While compiling HAML in #{path}"] << e.backtrace - rescue Exception => e + rescue StandardError, LoadError => e tracker.error e.exception(e.message + "\nWhile processing #{path}"), e.backtrace end end @@ -339,7 +339,7 @@ class Brakeman::Scanner @processor.process_model(parse_ruby(@app_tree.read_path(path)), path) rescue Racc::ParseError => e tracker.error e, "could not parse #{path}" - rescue Exception => e + rescue => e tracker.error e.exception(e.message + "\nWhile processing #{path}"), e.backtrace end end diff --git a/lib/ruby_parser/bm_sexp_processor.rb b/lib/ruby_parser/bm_sexp_processor.rb index be013a17..e26efc7b 100644 --- a/lib/ruby_parser/bm_sexp_processor.rb +++ b/lib/ruby_parser/bm_sexp_processor.rb @@ -88,7 +88,7 @@ class Brakeman::SexpProcessor def error_handler(type, exp=nil) # :nodoc: begin return yield - rescue StandardError => err + rescue => err warn "#{err.class} Exception thrown while processing #{type} for sexp #{exp.inspect} #{caller.inspect}" if $DEBUG raise end -- GitLab