diff options
author | Agis- <corestudiosinc@gmail.com> | 2015-09-01 23:11:35 +0300 |
---|---|---|
committer | Agis- <corestudiosinc@gmail.com> | 2015-09-02 00:30:59 +0300 |
commit | d1e9e01109bdab9d027a14152f65655b2f66af00 (patch) | |
tree | 5cb021b83ad0857c45c68f7ad364d9448931907d | |
parent | 21059b4ec2af38bf7ef9ddc233ca393259c97a9b (diff) | |
download | bundler-d1e9e01109bdab9d027a14152f65655b2f66af00.tar.gz |
Distinguish Gemfile syntax and evaluation errors
Fixes #3783.
-rwxr-xr-x | exe/bundle_ruby | 2 | ||||
-rw-r--r-- | lib/bundler.rb | 1 | ||||
-rw-r--r-- | lib/bundler/dsl.rb | 5 | ||||
-rw-r--r-- | lib/bundler/ruby_dsl.rb | 2 | ||||
-rw-r--r-- | spec/bundler/dsl_spec.rb | 8 |
5 files changed, 16 insertions, 2 deletions
diff --git a/exe/bundle_ruby b/exe/bundle_ruby index 9356d7ed8d..9bee595265 100755 --- a/exe/bundle_ruby +++ b/exe/bundle_ruby @@ -8,6 +8,8 @@ require "bundler/shared_helpers" module Bundler class GemfileError < RuntimeError; end + class GemfileEvalError < GemfileError; end + class Dsl include RubyDsl diff --git a/lib/bundler.rb b/lib/bundler.rb index eacee447e0..d943df9342 100644 --- a/lib/bundler.rb +++ b/lib/bundler.rb @@ -96,6 +96,7 @@ module Bundler status_code(24) end + class GemfileEvalError < GemfileError; end class MarshalError < StandardError; end class PermissionError < BundlerError diff --git a/lib/bundler/dsl.rb b/lib/bundler/dsl.rb index 9df01fb905..2da9de4da1 100644 --- a/lib/bundler/dsl.rb +++ b/lib/bundler/dsl.rb @@ -33,7 +33,10 @@ module Bundler contents ||= Bundler.read_file(gemfile.to_s) instance_eval(contents, gemfile.to_s, 1) rescue Exception => e - message = "There was an error parsing `#{File.basename gemfile.to_s}`: #{e.message}" + message = "There was an error " \ + "#{e.is_a?(GemfileEvalError) ? "evaluating" : "parsing"} " \ + "`#{File.basename gemfile.to_s}`: #{e.message}" + raise DSLError.new(message, gemfile, e.backtrace, contents) end diff --git a/lib/bundler/ruby_dsl.rb b/lib/bundler/ruby_dsl.rb index b29fc019a7..46587e98cf 100644 --- a/lib/bundler/ruby_dsl.rb +++ b/lib/bundler/ruby_dsl.rb @@ -4,7 +4,7 @@ module Bundler raise GemfileError, "Please define :engine_version" if options[:engine] && options[:engine_version].nil? raise GemfileError, "Please define :engine" if options[:engine_version] && options[:engine].nil? - raise GemfileError, "ruby_version must match the :engine_version for MRI" if options[:engine] == "ruby" && options[:engine_version] && ruby_version != options[:engine_version] + raise GemfileEvalError, "ruby_version must match the :engine_version for MRI" if options[:engine] == "ruby" && options[:engine_version] && ruby_version != options[:engine_version] @ruby_version = RubyVersion.new(ruby_version, options[:patchlevel], options[:engine], options[:engine_version]) end end diff --git a/spec/bundler/dsl_spec.rb b/spec/bundler/dsl_spec.rb index fc31531602..00242f037f 100644 --- a/spec/bundler/dsl_spec.rb +++ b/spec/bundler/dsl_spec.rb @@ -81,6 +81,14 @@ describe Bundler::Dsl do expect { subject.eval_gemfile("Gemfile") }. to raise_error(Bundler::GemfileError, /There was an error parsing `Gemfile`: (syntax error, unexpected tSTRING_DEND|(compile error - )?syntax error, unexpected '}'). Bundler cannot continue./) end + + it "distinguishes syntax errors from evaluation errors" do + expect(Bundler).to receive(:read_file).with("Gemfile").and_return( + "ruby '2.1.5', :engine => 'ruby', :engine_version => '1.2.4'" + ) + expect { subject.eval_gemfile("Gemfile") }. + to raise_error(Bundler::GemfileError, /There was an error evaluating `Gemfile`: ruby_version must match the :engine_version for MRI/) + end end describe "#gem" do |