summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAgis Anastasopoulos <agis.anast@gmail.com>2015-10-28 15:30:22 +0200
committerAgis Anastasopoulos <agis.anast@gmail.com>2015-10-28 15:43:19 +0200
commitdf6f695a28292787640a4d9489d56c57e8c6ca2d (patch)
treea4aaaa8243ea70a8d3b4d63341098ecbb350c292
parent9e6f9d88b91d9d0644ee610d7cea09aebc43751f (diff)
downloadbundler-handle-psych-errors.tar.gz
Handle invalid RubyGems config fileshandle-psych-errors
Fixes #4042.
-rw-r--r--lib/bundler/friendly_errors.rb4
-rw-r--r--lib/bundler/rubygems_integration.rb4
-rw-r--r--spec/bundler/friendly_errors_spec.rb27
3 files changed, 35 insertions, 0 deletions
diff --git a/lib/bundler/friendly_errors.rb b/lib/bundler/friendly_errors.rb
index e60f73f7df..f6f8fd5623 100644
--- a/lib/bundler/friendly_errors.rb
+++ b/lib/bundler/friendly_errors.rb
@@ -5,6 +5,10 @@ require "bundler/vendored_thor"
module Bundler
def self.with_friendly_errors
yield
+ rescue YAMLSyntaxError => e
+ Bundler.ui.error e.message
+ Bundler.ui.trace e.orig_exception
+ exit e.status_code
rescue Bundler::Dsl::DSLError => e
Bundler.ui.error e.message
exit e.status_code
diff --git a/lib/bundler/rubygems_integration.rb b/lib/bundler/rubygems_integration.rb
index f4c2a12d9d..648616acf0 100644
--- a/lib/bundler/rubygems_integration.rb
+++ b/lib/bundler/rubygems_integration.rb
@@ -1,6 +1,7 @@
require "monitor"
require "rubygems"
require "rubygems/config_file"
+require "bundler/psyched_yaml"
module Bundler
class RubygemsIntegration
@@ -67,6 +68,9 @@ module Bundler
Bundler.ui.error "#{e.class}: #{e.message}"
Bundler.ui.trace e
raise
+ rescue YamlSyntaxError => e
+ raise YAMLSyntaxError.new(e, "Your RubyGems configuration, which is " \
+ "usually located in ~/.gemrc, contains invalid YAML syntax.")
end
def ruby_engine
diff --git a/spec/bundler/friendly_errors_spec.rb b/spec/bundler/friendly_errors_spec.rb
index ee0667cb2f..2eca85eb84 100644
--- a/spec/bundler/friendly_errors_spec.rb
+++ b/spec/bundler/friendly_errors_spec.rb
@@ -3,6 +3,33 @@ require "bundler"
require "bundler/friendly_errors"
describe Bundler, "friendly errors" do
+ context "with invalid YAML in .gemrc" do
+ before do
+ File.open(Gem.configuration.config_file_name, "w") do |f|
+ f.write "invalid: yaml: hah"
+ end
+ end
+
+ after do
+ FileUtils.rm(Gem.configuration.config_file_name)
+ end
+
+ it "reports a relevant friendly error message", :ruby => ">= 1.9" do
+ gemfile <<-G
+ source "file://#{gem_repo1}"
+ gem "rack"
+ G
+
+ bundle :install, :env => { "DEBUG" => true }
+
+ expect(out).to include("Your RubyGems configuration")
+ expect(out).to include("invalid YAML syntax")
+ expect(out).to include("Psych::SyntaxError")
+ expect(out).not_to include("ERROR REPORT TEMPLATE")
+ expect(exitstatus).to eq(25) if exitstatus
+ end
+ end
+
it "rescues Thor::AmbiguousTaskError and raises SystemExit" do
expect {
Bundler.with_friendly_errors do