Permalink
Browse files

extract rescue logic in bin/bundle

paired with @wycats
  • Loading branch information...
1 parent f96d7e7 commit fe86387130d7b809f15d0f344a8e9ac7f6ad86e0 @hone hone committed May 25, 2012
Showing with 33 additions and 27 deletions.
  1. +9 −27 bin/bundle
  2. +24 −0 lib/bundler/friendly_errors.rb
View
@@ -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 }
@@ -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

0 comments on commit fe86387

Please sign in to comment.