summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHomu <homu@barosl.com>2015-09-03 10:38:24 +0900
committerHomu <homu@barosl.com>2015-09-03 10:38:24 +0900
commit9d61e4ff81114e6e42bc4d40305c4f993b1a7988 (patch)
tree6fd295fde05f1b077110e2f41b0c4856a2e0b6f6
parent4cc8417a68c72e61d477b4f7d8feaeab692025ea (diff)
parentd1e9e01109bdab9d027a14152f65655b2f66af00 (diff)
downloadbundler-9d61e4ff81114e6e42bc4d40305c4f993b1a7988.tar.gz
Auto merge of #3971 - agis-:issue-3783, r=indirect
Distinguish Gemfile syntax and evaluation errors Fixes #3783.
-rwxr-xr-xexe/bundle_ruby2
-rw-r--r--lib/bundler.rb1
-rw-r--r--lib/bundler/dsl.rb5
-rw-r--r--lib/bundler/ruby_dsl.rb2
-rw-r--r--spec/bundler/dsl_spec.rb8
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 b7b43ed8e0..28d488dc18 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