diff options
author | Terence Lee <hone02@gmail.com> | 2012-05-25 01:19:40 -0500 |
---|---|---|
committer | Terence Lee <hone02@gmail.com> | 2012-05-25 01:35:22 -0500 |
commit | fe86387130d7b809f15d0f344a8e9ac7f6ad86e0 (patch) | |
tree | 5a32dcee5391403f91bb86ef49b34778dbfeb880 | |
parent | f96d7e75121563bf2a3a45db9d4d9d775ab0be56 (diff) | |
download | bundler-fe86387130d7b809f15d0f344a8e9ac7f6ad86e0.tar.gz |
extract rescue logic in bin/bundle
paired with @wycats
-rwxr-xr-x | bin/bundle | 36 | ||||
-rw-r--r-- | lib/bundler/friendly_errors.rb | 24 |
2 files changed, 33 insertions, 27 deletions
@@ -1,31 +1,13 @@ #!/usr/bin/env ruby require 'bundler' -begin - # Check if an older version of bundler is installed - $:.each do |path| - if path =~ %r'/bundler-0.(\d+)' && $1.to_i < 9 - err = "Please remove Bundler 0.8 versions." - err << "This can be done by running `gem cleanup bundler`." - abort(err) - end +# Check if an older version of bundler is installed +$:.each do |path| + if path =~ %r'/bundler-0.(\d+)' && $1.to_i < 9 + err = "Please remove Bundler 0.8 versions." + err << "This can be done by running `gem cleanup bundler`." + abort(err) end - require 'bundler/cli' - Bundler::CLI.start -rescue Bundler::BundlerError => e - Bundler.ui.error e.message - Bundler.ui.debug e.backtrace.join("\n") - exit e.status_code -rescue Interrupt => e - Bundler.ui.error "\nQuitting..." - Bundler.ui.debug e.backtrace.join("\n") - exit 1 -rescue SystemExit => e - exit e.status -rescue Exception => e - Bundler.ui.error "Unfortunately, a fatal error has occurred. " + - "Please report this error to the Bundler issue tracker at " + - "https://github.com/carlhuda/bundler/issues so that we can fix it. " + - "Please include the full output of the command, your Gemfile and Gemfile.lock. " + - "Thanks!" - raise e end +require 'bundler/cli' +require 'bundler/friendly_errors' +Bundler.with_friendly_errors {Bundler::CLI.start } diff --git a/lib/bundler/friendly_errors.rb b/lib/bundler/friendly_errors.rb new file mode 100644 index 00000000..6bff6164 --- /dev/null +++ b/lib/bundler/friendly_errors.rb @@ -0,0 +1,24 @@ +module Bundler + def self.with_friendly_errors + begin + yield + rescue Bundler::BundlerError => e + Bundler.ui.error e.message + Bundler.ui.debug e.backtrace.join("\n") + exit e.status_code + rescue Interrupt => e + Bundler.ui.error "\nQuitting..." + Bundler.ui.debug e.backtrace.join("\n") + exit 1 + rescue SystemExit => e + exit e.status + rescue Exception => e + Bundler.ui.error "Unfortunately, a fatal error has occurred. " + + "Please report this error to the Bundler issue tracker at " + + "https://github.com/carlhuda/bundler/issues so that we can fix it. " + + "Please include the full output of the command, your Gemfile and Gemfile.lock. " + + "Thanks!" + raise e + end + end +end |