diff --git a/bin/brakeman b/bin/brakeman index 7ac2012341dd5aef10d5b7af213552d228966613..f7e618e39d696fbb65f0f66e795b4e2180170f2e 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 8184eb7469cb90c971261b428151da364f2fc0cc..509775e5a10e8cb1d620c351ded284a4514cb849 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