summaryrefslogtreecommitdiff
path: root/lib/bundler
diff options
context:
space:
mode:
authorAgis- <corestudiosinc@gmail.com>2015-08-28 23:39:13 +0300
committerAgis- <corestudiosinc@gmail.com>2015-08-29 11:54:39 +0300
commitf668e28c19886ffa4680c4ac58e6bf58a3ebccde (patch)
tree509fc5a7d2f9eb5372cee01a95965a9aea03d1fb /lib/bundler
parentfa9c4e2343ebeaaa4e0eb62c41327eba37cca9ee (diff)
downloadbundler-f668e28c19886ffa4680c4ac58e6bf58a3ebccde.tar.gz
Handle errors when requiring gems gracefully
Fixes #3960.
Diffstat (limited to 'lib/bundler')
-rw-r--r--lib/bundler/friendly_errors.rb4
-rw-r--r--lib/bundler/runtime.rb8
-rw-r--r--lib/bundler/ui/shell.rb4
3 files changed, 13 insertions, 3 deletions
diff --git a/lib/bundler/friendly_errors.rb b/lib/bundler/friendly_errors.rb
index 0a90ca506e..53125fd99c 100644
--- a/lib/bundler/friendly_errors.rb
+++ b/lib/bundler/friendly_errors.rb
@@ -8,6 +8,10 @@ module Bundler
rescue Bundler::Dsl::DSLError => e
Bundler.ui.error e.message
exit e.status_code
+ rescue Bundler::GemRequireError => e
+ Bundler.ui.error e.message
+ Bundler.ui.trace e.orig_exception, nil, true
+ exit e.status_code
rescue Bundler::BundlerError => e
Bundler.ui.error e.message, :wrap => true
Bundler.ui.trace e
diff --git a/lib/bundler/runtime.rb b/lib/bundler/runtime.rb
index 5f340a3e64..5e87ee7cc3 100644
--- a/lib/bundler/runtime.rb
+++ b/lib/bundler/runtime.rb
@@ -73,7 +73,13 @@ module Bundler
# Allow `require: true` as an alias for `require: <name>`
file = dep.name if file == true
required_file = file
- Kernel.require file
+ begin
+ Kernel.require file
+ rescue => e
+ raise e if e.is_a?(LoadError) # we handle this a little later
+ raise Bundler::GemRequireError.new e,
+ "There was an error while trying to load the gem '#{file}'."
+ end
end
rescue LoadError => e
REQUIRE_ERRORS.find {|r| r =~ e.message }
diff --git a/lib/bundler/ui/shell.rb b/lib/bundler/ui/shell.rb
index 92af57756c..65460f2fdb 100644
--- a/lib/bundler/ui/shell.rb
+++ b/lib/bundler/ui/shell.rb
@@ -68,8 +68,8 @@ module Bundler
name ? LEVELS.index(name) <= LEVELS.index(@level) : @level
end
- def trace(e, newline = nil)
- return unless debug?
+ def trace(e, newline = nil, force = false)
+ return unless debug? || force
msg = "#{e.class}: #{e.message}\n#{e.backtrace.join("\n ")}"
tell_me(msg, nil, newline)
end