diff options
Diffstat (limited to 'lib/bundler/friendly_errors.rb')
-rw-r--r-- | lib/bundler/friendly_errors.rb | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/lib/bundler/friendly_errors.rb b/lib/bundler/friendly_errors.rb index cc615db60c..e61ed64450 100644 --- a/lib/bundler/friendly_errors.rb +++ b/lib/bundler/friendly_errors.rb @@ -29,18 +29,18 @@ module Bundler Bundler.ui.error error.message Bundler.ui.trace error.orig_exception when BundlerError - Bundler.ui.error error.message, :wrap => true - Bundler.ui.trace error + if Bundler.ui.debug? + Bundler.ui.trace error + else + Bundler.ui.error error.message, wrap: true + end when Thor::Error Bundler.ui.error error.message - when LoadError - raise error unless error.message =~ /cannot load such file -- openssl|openssl.so|libcrypto.so/ - Bundler.ui.error "\nCould not load OpenSSL. #{error.class}: #{error}\n#{error.backtrace.join("\n ")}" when Interrupt Bundler.ui.error "\nQuitting..." Bundler.ui.trace error when Gem::InvalidSpecificationException - Bundler.ui.error error.message, :wrap => true + Bundler.ui.error error.message, wrap: true when SystemExit when *[defined?(Java::JavaLang::OutOfMemoryError) && Java::JavaLang::OutOfMemoryError].compact Bundler.ui.error "\nYour JVM has run out of memory, and Bundler cannot continue. " \ @@ -61,12 +61,11 @@ module Bundler end def request_issue_report_for(e) - Bundler.ui.error <<-EOS.gsub(/^ {8}/, ""), nil, nil + Bundler.ui.error <<~EOS, nil, nil --- ERROR REPORT TEMPLATE ------------------------------------------------------- ``` - #{e.class}: #{e.message} - #{e.backtrace && e.backtrace.join("\n ").chomp} + #{exception_message(e)} ``` #{Bundler::Env.report} @@ -76,7 +75,7 @@ module Bundler Bundler.ui.error "Unfortunately, an unexpected error occurred, and Bundler cannot continue." - Bundler.ui.error <<-EOS.gsub(/^ {8}/, ""), nil, :yellow + Bundler.ui.error <<~EOS, nil, :yellow First, try this link to see if there are any existing issue reports for this error: #{issues_url(e)} @@ -85,6 +84,21 @@ module Bundler EOS end + def exception_message(error) + message = serialized_exception_for(error) + cause = error.cause + return message unless cause + + message + serialized_exception_for(cause) + end + + def serialized_exception_for(e) + <<~EOS + #{e.class}: #{e.message} + #{e.backtrace&.join("\n ")&.chomp} + EOS + end + def issues_url(exception) message = exception.message.lines.first.tr(":", " ").chomp message = message.split("-").first if exception.is_a?(Errno) |