Skip to content

Commit

Permalink
(bug) - Fix ruby 3.x incompatibility
Browse files Browse the repository at this point in the history
It was noted that this gem was failing spec tests when running on ruby 3.x and above.
The root cause of this issue seemed to be the absolute_path property found on the Thread::Backtrace::Location class.
Updating this to path allows spec tests to pass on both ruby 2.x and 3.x.

Can confirm that when consumed by other tools, this also works as expected. Open to suggested changes and improvements.
  • Loading branch information
jordanbreen28 committed Oct 26, 2023
1 parent 8008a19 commit 273d4b0
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/puppetfile-resolver/puppetfile/parser/r10k_eval.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def self.parse(puppetfile_contents)
rescue StandardError, LoadError => e
# Find the originating error from within the puppetfile
loc = e.backtrace_locations
.select { |item| item.absolute_path == PUPPETFILE_MONIKER }
.select { |item| item.path == PUPPETFILE_MONIKER }
.first
start_line_number = loc.nil? ? 0 : loc.lineno - 1 # Line numbers from ruby are base 1
end_line_number = loc.nil? ? puppetfile_contents.lines.count - 1 : loc.lineno - 1 # Line numbers from ruby are base 1
Expand Down
2 changes: 1 addition & 1 deletion lib/puppetfile-resolver/puppetfile/parser/r10k_eval/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def method_missing(method_name, *_args) # rubocop:disable Style/MethodMissingSup

def find_load_line_number
loc = Kernel.caller_locations
.find { |call_loc| call_loc.absolute_path == ::PuppetfileResolver::Puppetfile::Parser::R10KEval::PUPPETFILE_MONIKER }
.find { |call_loc| call_loc.path == ::PuppetfileResolver::Puppetfile::Parser::R10KEval::PUPPETFILE_MONIKER }
loc.nil? ? 0 : loc.lineno - 1 # Line numbers from ruby are base 1
end
end
Expand Down

0 comments on commit 273d4b0

Please sign in to comment.