diff options
author | Samuel Giddins <segiddins@segiddins.me> | 2016-07-14 22:00:09 -0500 |
---|---|---|
committer | Samuel Giddins <segiddins@segiddins.me> | 2016-07-20 09:35:41 -0500 |
commit | 85f7252bc4e57c1d85e5fb1c2a808b90e209bb2b (patch) | |
tree | b1cd66888db41b92f519f0734a62b644106129aa | |
parent | 396c9a5d6da3835ce21cccaadd5ae4fb0e781dba (diff) | |
download | bundler-85f7252bc4e57c1d85e5fb1c2a808b90e209bb2b.tar.gz |
[Bundler] Use DSLError when eval-ing a gemspec fails
-rw-r--r-- | lib/bundler.rb | 10 | ||||
-rw-r--r-- | lib/bundler/dsl.rb | 2 | ||||
-rw-r--r-- | lib/bundler/friendly_errors.rb | 2 | ||||
-rw-r--r-- | spec/bundler/bundler_spec.rb | 2 | ||||
-rw-r--r-- | spec/install/gemfile/sources_spec.rb | 2 | ||||
-rw-r--r-- | spec/runtime/setup_spec.rb | 15 |
6 files changed, 16 insertions, 17 deletions
diff --git a/lib/bundler.rb b/lib/bundler.rb index 07064dadb6..bedc0464e6 100644 --- a/lib/bundler.rb +++ b/lib/bundler.rb @@ -401,17 +401,13 @@ module Bundler def eval_gemspec(path, contents) eval(contents, TOPLEVEL_BINDING, path.expand_path.to_s) rescue ScriptError, StandardError => e - original_line = e.backtrace.find {|line| line.include?(path.to_s) } - msg = String.new - msg << "There was a #{e.class} while loading #{path.basename}: \n#{e.message}" - msg << " from\n #{original_line}" if original_line - msg << "\n" + msg = "There was an error while loading `#{path.basename}`: #{e.message}" if e.is_a?(LoadError) && RUBY_VERSION >= "1.9" - msg << "\nDoes it try to require a relative path? That's been removed in Ruby 1.9." + msg += "\nDoes it try to require a relative path? That's been removed in Ruby 1.9" end - raise GemspecError, msg + raise GemspecError, Dsl::DSLError.new(msg, path, e.backtrace, contents) end def configure_gem_home_and_path diff --git a/lib/bundler/dsl.rb b/lib/bundler/dsl.rb index 0436b58f3a..58ff752f35 100644 --- a/lib/bundler/dsl.rb +++ b/lib/bundler/dsl.rb @@ -417,7 +417,7 @@ module Bundler # TODO: 2.0 upgrade from setting to default if Bundler.settings[:disable_multisource] - raise GemspecError, "Warning: this Gemfile contains multiple primary sources. " \ + raise GemfileError, "Warning: this Gemfile contains multiple primary sources. " \ "Each source after the first must include a block to indicate which gems " \ "should come from that source. To downgrade this error to a warning, run " \ "`bundle config --delete disable_multisource`" diff --git a/lib/bundler/friendly_errors.rb b/lib/bundler/friendly_errors.rb index a01c03f25c..b6c22ee60e 100644 --- a/lib/bundler/friendly_errors.rb +++ b/lib/bundler/friendly_errors.rb @@ -12,7 +12,7 @@ module Bundler when YamlSyntaxError Bundler.ui.error error.message Bundler.ui.trace error.orig_exception - when Dsl::DSLError + when Dsl::DSLError, GemspecError Bundler.ui.error error.message when GemRequireError Bundler.ui.error error.message diff --git a/spec/bundler/bundler_spec.rb b/spec/bundler/bundler_spec.rb index f338b5268d..34f559e702 100644 --- a/spec/bundler/bundler_spec.rb +++ b/spec/bundler/bundler_spec.rb @@ -19,7 +19,7 @@ describe Bundler do end it "catches YAML syntax errors" do - expect { subject }.to raise_error(Bundler::GemspecError) + expect { subject }.to raise_error(Bundler::GemspecError, /error while loading `test.gemspec`/) end context "on Rubies with a settable YAML engine", :if => defined?(YAML::ENGINE) do diff --git a/spec/install/gemfile/sources_spec.rb b/spec/install/gemfile/sources_spec.rb index 70ea9e30ce..7b44f5932a 100644 --- a/spec/install/gemfile/sources_spec.rb +++ b/spec/install/gemfile/sources_spec.rb @@ -42,7 +42,7 @@ describe "bundle install with gems on multiple sources" do bundle "config disable_multisource true" bundle :install expect(out).to include("Each source after the first must include a block") - expect(exitstatus).to eq(14) if exitstatus + expect(exitstatus).to eq(4) if exitstatus end end diff --git a/spec/runtime/setup_spec.rb b/spec/runtime/setup_spec.rb index 18abf0549e..5a4ca2ac05 100644 --- a/spec/runtime/setup_spec.rb +++ b/spec/runtime/setup_spec.rb @@ -922,14 +922,17 @@ describe "Bundler.setup" do end it "error intelligently if the gemspec has a LoadError" do - update_git "bar", :gemspec => false do |s| + ref = update_git "bar", :gemspec => false do |s| s.write "bar.gemspec", "require 'foobarbaz'" - end + end.ref_for("HEAD") bundle :install - expect(out).to include("was a LoadError while loading bar.gemspec") - expect(out).to include("foobarbaz") - expect(out).to include("bar.gemspec:1") - expect(out).to include("try to require a relative path") if RUBY_VERSION >= "1.9" + puts out + expect(out.lines.map(&:chomp)).to include( + a_string_starting_with("[!] There was an error while loading `bar.gemspec`:"), + RUBY_VERSION >= "1.9" ? a_string_starting_with("Does it try to require a relative path? That's been removed in Ruby 1.9.") : "", + " # from #{default_bundle_path "bundler", "gems", "bar-1.0-#{ref[0, 12]}", "bar.gemspec"}:1", + " > require 'foobarbaz'" + ) end it "evals each gemspec with a binding from the top level" do |