reek icon indicating copy to clipboard operation
reek copied to clipboard

Fix load error with REXML document

Open bkuhlmann opened this issue 2 years ago • 3 comments

Overview

Hello. 👋 I stumbled across an issue where I can't include Reek as a gem unless RuboCop is also required. I can see that Reek::Report::XMLReport requires rexml/document but there appears to be an order of operation issue where REXML isn't loaded in time.

Steps to Recreate

You can run the following script to reproduce:

#! /usr/bin/env ruby
# frozen_string_literal: true

# Save as `snippet`, then `chmod 755 snippet`, and run as `./snippet`.

require "bundler/inline"

gemfile true do
  source "https://rubygems.org"
  gem "reek"
end

puts "Failed to make it here. 😢"

Upon running ./snippet, I'll get the following output:

Stack Dump
Fetching gem metadata from https://rubygems.org/........
Resolving dependencies...
Using ast 2.4.2
Using bundler 2.4.6
Using kwalify 0.7.2
Using rainbow 3.1.1
Using parser 3.2.0.0
Using reek 6.1.4
<internal:/Users/bkuhlmann/.cache/frum/versions/3.2.0/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require': cannot load such file -- rexml/document (LoadError)
	from <internal:/Users/bkuhlmann/.cache/frum/versions/3.2.0/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
	from /Users/bkuhlmann/.cache/frum/versions/3.2.0/lib/ruby/gems/3.2.0/gems/reek-6.1.4/lib/reek/report/xml_report.rb:13:in `<class:XMLReport>'
	from /Users/bkuhlmann/.cache/frum/versions/3.2.0/lib/ruby/gems/3.2.0/gems/reek-6.1.4/lib/reek/report/xml_report.rb:12:in `<module:Report>'
	from /Users/bkuhlmann/.cache/frum/versions/3.2.0/lib/ruby/gems/3.2.0/gems/reek-6.1.4/lib/reek/report/xml_report.rb:6:in `<module:Reek>'
	from /Users/bkuhlmann/.cache/frum/versions/3.2.0/lib/ruby/gems/3.2.0/gems/reek-6.1.4/lib/reek/report/xml_report.rb:5:in `<top (required)>'
	from /Users/bkuhlmann/.cache/frum/versions/3.2.0/lib/ruby/gems/3.2.0/gems/reek-6.1.4/lib/reek/report.rb:6:in `require_relative'
	from /Users/bkuhlmann/.cache/frum/versions/3.2.0/lib/ruby/gems/3.2.0/gems/reek-6.1.4/lib/reek/report.rb:6:in `<top (required)>'
	from /Users/bkuhlmann/.cache/frum/versions/3.2.0/lib/ruby/gems/3.2.0/gems/reek-6.1.4/lib/reek.rb:8:in `require_relative'
	from /Users/bkuhlmann/.cache/frum/versions/3.2.0/lib/ruby/gems/3.2.0/gems/reek-6.1.4/lib/reek.rb:8:in `<top (required)>'
	from /Users/bkuhlmann/.cache/frum/versions/3.2.0/lib/ruby/site_ruby/3.2.0/bundler/runtime.rb:60:in `require'
	from /Users/bkuhlmann/.cache/frum/versions/3.2.0/lib/ruby/site_ruby/3.2.0/bundler/runtime.rb:60:in `block (2 levels) in require'
	from /Users/bkuhlmann/.cache/frum/versions/3.2.0/lib/ruby/site_ruby/3.2.0/bundler/runtime.rb:55:in `each'
	from /Users/bkuhlmann/.cache/frum/versions/3.2.0/lib/ruby/site_ruby/3.2.0/bundler/runtime.rb:55:in `block in require'
	from /Users/bkuhlmann/.cache/frum/versions/3.2.0/lib/ruby/site_ruby/3.2.0/bundler/runtime.rb:44:in `each'
	from /Users/bkuhlmann/.cache/frum/versions/3.2.0/lib/ruby/site_ruby/3.2.0/bundler/runtime.rb:44:in `require'
	from /Users/bkuhlmann/.cache/frum/versions/3.2.0/lib/ruby/site_ruby/3.2.0/bundler/inline.rb:66:in `block (2 levels) in gemfile'
	from /Users/bkuhlmann/.cache/frum/versions/3.2.0/lib/ruby/site_ruby/3.2.0/bundler/settings.rb:131:in `temporary'
	from /Users/bkuhlmann/.cache/frum/versions/3.2.0/lib/ruby/site_ruby/3.2.0/bundler/inline.rb:51:in `block in gemfile'
	from /Users/bkuhlmann/.cache/frum/versions/3.2.0/lib/ruby/site_ruby/3.2.0/bundler.rb:418:in `block in with_unbundled_env'
	from /Users/bkuhlmann/.cache/frum/versions/3.2.0/lib/ruby/site_ruby/3.2.0/bundler.rb:664:in `with_env'
	from /Users/bkuhlmann/.cache/frum/versions/3.2.0/lib/ruby/site_ruby/3.2.0/bundler.rb:418:in `with_unbundled_env'
	from /Users/bkuhlmann/.cache/frum/versions/3.2.0/lib/ruby/site_ruby/3.2.0/bundler/inline.rb:42:in `gemfile'
	from /Users/bkuhlmann/Engineering/Misc/snippet:8:in `<main>'

Environment

  • Ruby: ruby 3.2.0 (2022-12-25 revision a528908271) +YJIT [arm64-darwin22.2.0]
  • Reek: 6.1.4

bkuhlmann avatar Feb 05 '23 17:02 bkuhlmann

Thanks, @bkuhlmann. We probably missed this because RuboCop is part of the bundle in development.

mvz avatar Feb 06 '23 12:02 mvz

I found this independently on our project the other day but had forgotten to come here and report it. 😂

Worked fine after adding rexml to our Gemfile, so that seems to be the only missing dependency.

hakanai avatar Feb 07 '23 23:02 hakanai

Hey @mvz this dependency was added: https://github.com/troessner/reek/pull/1703/files But it does not seem like it is included in the 6.1.4 release: https://github.com/troessner/reek/blob/v6.1.4/reek.gemspec We should probably release a new minor version with rexml included.

Also, we did not add anything about it to the CHANGELOG. So I wonder if we should add a note about it to the CHANGELOG.

fbuys avatar Oct 06 '23 20:10 fbuys

In the mean time, Reek 6.2.0 has been released which includes the rexml dependency in the gemspec.

mvz avatar May 31 '24 18:05 mvz

Thanks! Actually, you mean Reek 6.3.0 but understand what you mean. :wink:

bkuhlmann avatar May 31 '24 18:05 bkuhlmann

No I meant 6.2.0 because it already includes the change :smile:

mvz avatar Jun 01 '24 04:06 mvz

Oh, sorry, I should have double checked. I thought this functionality rolled out in 6.3.0 but it was 6.2.0. I stand corrected! 😊

bkuhlmann avatar Jun 01 '24 12:06 bkuhlmann