diff options
author | Homu <homu@barosl.com> | 2015-10-29 02:13:05 +0900 |
---|---|---|
committer | Homu <homu@barosl.com> | 2015-10-29 02:13:05 +0900 |
commit | 617d8f07cd4f36e60cd0c4a767a1568064fcbeee (patch) | |
tree | a4aaaa8243ea70a8d3b4d63341098ecbb350c292 | |
parent | 9e6f9d88b91d9d0644ee610d7cea09aebc43751f (diff) | |
parent | df6f695a28292787640a4d9489d56c57e8c6ca2d (diff) | |
download | bundler-617d8f07cd4f36e60cd0c4a767a1568064fcbeee.tar.gz |
Auto merge of #4076 - bundler:handle-psych-errors, r=segiddins
Handle invalid RubyGems config files
Fixes #4042.
-rw-r--r-- | lib/bundler/friendly_errors.rb | 4 | ||||
-rw-r--r-- | lib/bundler/rubygems_integration.rb | 4 | ||||
-rw-r--r-- | spec/bundler/friendly_errors_spec.rb | 27 |
3 files changed, 35 insertions, 0 deletions
diff --git a/lib/bundler/friendly_errors.rb b/lib/bundler/friendly_errors.rb index e60f73f7..f6f8fd56 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 f4c2a12d..648616ac 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 ee0667cb..2eca85eb 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 |