@@ -42,20 +42,20 @@ def initialize
4242 end
4343
4444 def eval_gemfile ( gemfile , contents = nil )
45- expanded_gemfile_path = Pathname . new ( gemfile ) . expand_path ( @gemfile &. parent )
46- original_gemfile = @gemfile
47- @gemfile = expanded_gemfile_path
48- @gemfiles << expanded_gemfile_path
49- contents ||= Bundler . read_file ( @gemfile . to_s )
50- instance_eval ( contents , @gemfile . to_s , 1 )
51- rescue Exception => e # rubocop:disable Lint/RescueException
52- message = "There was an error " \
53- " #{ e . is_a? ( GemfileEvalError ) ? "evaluating" : "parsing" } " \
54- "` #{ File . basename gemfile . to_s } `: #{ e . message } "
55-
56- raise DSLError . new ( message , gemfile , e . backtrace , contents )
57- ensure
58- @gemfile = original_gemfile
45+ with_gemfile ( gemfile ) do | current_gemfile |
46+ contents ||= Bundler . read_file ( current_gemfile )
47+ instance_eval ( contents , current_gemfile , 1 )
48+ rescue GemfileEvalError => e
49+ message = "There was an error evaluating ` #{ File . basename current_gemfile } `: #{ e . message } "
50+ raise DSLError . new ( message , current_gemfile , e . backtrace , contents )
51+ rescue GemfileError , InvalidArgumentError , InvalidOption , DeprecatedError , ScriptError => e
52+ message = "There was an error parsing ` #{ File . basename current_gemfile } `: #{ e . message } "
53+ raise DSLError . new ( message , current_gemfile , e . backtrace , contents )
54+ rescue StandardError => e
55+ raise unless e . backtrace_locations . first . path == current_gemfile
56+ message = "There was an error parsing ` #{ File . basename current_gemfile } `: #{ e . message } "
57+ raise DSLError . new ( message , current_gemfile , e . backtrace , contents )
58+ end
5959 end
6060
6161 def gemspec ( opts = nil )
@@ -219,7 +219,7 @@ def git(uri, options = {}, &blk)
219219 end
220220
221221 def github ( repo , options = { } )
222- raise ArgumentError , "GitHub sources require a block" unless block_given?
222+ raise InvalidArgumentError , "GitHub sources require a block" unless block_given?
223223 github_uri = @git_sources [ "github" ] . call ( repo )
224224 git_options = normalize_hash ( options ) . merge ( "uri" => github_uri )
225225 git_source = @sources . add_git_source ( git_options )
@@ -285,6 +285,16 @@ def check_primary_source_safety
285285
286286 private
287287
288+ def with_gemfile ( gemfile )
289+ expanded_gemfile_path = Pathname . new ( gemfile ) . expand_path ( @gemfile &.parent )
290+ original_gemfile = @gemfile
291+ @gemfile = expanded_gemfile_path
292+ @gemfiles << expanded_gemfile_path
293+ yield @gemfile . to_s
294+ ensure
295+ @gemfile = original_gemfile
296+ end
297+
288298 def add_git_sources
289299 git_source ( :github ) do |repo_name |
290300 if repo_name =~ GITHUB_PULL_REQUEST_URL
@@ -577,7 +587,7 @@ def to_s
577587
578588 return m unless backtrace && dsl_path && contents
579589
580- trace_line = backtrace . find { |l | l . include? ( dsl_path . to_s ) } || trace_line
590+ trace_line = backtrace . find { |l | l . include? ( dsl_path ) } || trace_line
581591 return m unless trace_line
582592 line_numer = trace_line . split ( ":" ) [ 1 ] . to_i - 1
583593 return m unless line_numer
@@ -603,7 +613,7 @@ def to_s
603613
604614 def parse_line_number_from_description
605615 description = self . description
606- if dsl_path && description =~ /((#{ Regexp . quote File . expand_path ( dsl_path ) } |#{ Regexp . quote dsl_path . to_s } ):\d +)/
616+ if dsl_path && description =~ /((#{ Regexp . quote File . expand_path ( dsl_path ) } |#{ Regexp . quote dsl_path } ):\d +)/
607617 trace_line = Regexp . last_match [ 1 ]
608618 description = description . sub ( /\n .*\n (\. \. \. )? *\^ ~+$/ , "" ) . sub ( /#{ Regexp . quote trace_line } :\s */ , "" ) . sub ( "\n " , " - " )
609619 end
0 commit comments