From 7f7cae3f453e9410833091d6323c20ac9c6a8afc Mon Sep 17 00:00:00 2001 From: Justin Collins Date: Sat, 11 May 2013 09:10:24 -0700 Subject: [PATCH] Raise an exception if no app is found, not exit --- bin/brakeman | 31 ++++++++++++++++--------------- lib/brakeman/scanner.rb | 4 +++- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/bin/brakeman b/bin/brakeman index 7ac20123..f7e618e3 100755 --- a/bin/brakeman +++ b/bin/brakeman @@ -56,22 +56,23 @@ if options[:quiet].nil? options[:quiet] = :command_line end -if options[:previous_results_json] - vulns = Brakeman.compare options.merge(:quiet => options[:quiet]) - puts MultiJson.dump(vulns, :pretty => true) +begin + if options[:previous_results_json] + vulns = Brakeman.compare options.merge(:quiet => options[:quiet]) + puts MultiJson.dump(vulns, :pretty => true) - if options[:exit_on_warn] and (vulns[:new].count + vulns[:fixed].count > 0) - exit Brakeman::Warnings_Found_Exit_Code - end -else - #Run scan and output a report - tracker = Brakeman.run options.merge(:print_report => true, :quiet => options[:quiet]) + if options[:exit_on_warn] and (vulns[:new].count + vulns[:fixed].count > 0) + exit Brakeman::Warnings_Found_Exit_Code + end + else + #Run scan and output a report + tracker = Brakeman.run options.merge(:print_report => true, :quiet => options[:quiet]) - #Return error code if --exit-on-warn is used and warnings were found - if options[:exit_on_warn] and not tracker.checks.all_warnings.empty? - exit Brakeman::Warnings_Found_Exit_Code + #Return error code if --exit-on-warn is used and warnings were found + if options[:exit_on_warn] and not tracker.checks.all_warnings.empty? + exit Brakeman::Warnings_Found_Exit_Code + end end +rescue Brakeman::Scanner::NoApplication => e + $stderr.puts e.message end - - - diff --git a/lib/brakeman/scanner.rb b/lib/brakeman/scanner.rb index 8184eb74..509775e5 100644 --- a/lib/brakeman/scanner.rb +++ b/lib/brakeman/scanner.rb @@ -33,7 +33,7 @@ class Brakeman::Scanner @app_tree = Brakeman::AppTree.from_options(options) if !@app_tree.root || !@app_tree.exists?("app") - abort("Please supply the path to a Rails application.") + raise NoApplication, "Please supply the path to a Rails application." end if @app_tree.exists?("script/rails") @@ -355,4 +355,6 @@ class Brakeman::Scanner def parse_ruby input @ruby_parser.new.parse input end + + class NoApplication < RuntimeError; end end -- GitLab