Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

insert_into_file fails with "`merge': no implicit conversion of nil into Hash (TypeError)" when given no config #571

Closed
technicalpickles opened this issue Jul 24, 2017 · 1 comment · Fixed by #683

Comments

@technicalpickles
Copy link

I ran into this while writing a Rails template. Consider this small template:

# insert_into_file_test.rb
insert_into_file "some_file" do
  "hello this is content for some_file"
end

Running rails new -m insert_into_file_test.rb test-insert-into-file-test fails with:

       apply  /Users/technicalpickles/src/insert_into_file_test.rb
/Users/technicalpickles/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/thor-0.19.4/lib/thor/actions/inject_into_file.rb:35:in `merge': no implicit conversion of nil into Hash (TypeError)
	from /Users/technicalpickles/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/thor-0.19.4/lib/thor/actions/inject_into_file.rb:35:in `initialize'
	from /Users/technicalpickles/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/thor-0.19.4/lib/thor/actions/inject_into_file.rb:27:in `new'
	from /Users/technicalpickles/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/thor-0.19.4/lib/thor/actions/inject_into_file.rb:27:in `insert_into_file'
	from /Users/technicalpickles/src/insert_into_file_test.rb:1:in `apply'
	from /Users/technicalpickles/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/thor-0.19.4/lib/thor/actions.rb:224:in `instance_eval'
	from /Users/technicalpickles/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/thor-0.19.4/lib/thor/actions.rb:224:in `apply'
	from /Users/technicalpickles/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/railties-5.1.2/lib/rails/generators/app_base.rb:162:in `apply_rails_template'
	from (eval):1:in `apply_rails_template'
	from /Users/technicalpickles/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/thor-0.19.4/lib/thor/command.rb:27:in `run'
	from /Users/technicalpickles/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/thor-0.19.4/lib/thor/invocation.rb:126:in `invoke_command'
	from /Users/technicalpickles/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/thor-0.19.4/lib/thor/invocation.rb:133:in `block in invoke_all'
	from /Users/technicalpickles/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/thor-0.19.4/lib/thor/invocation.rb:133:in `each'
	from /Users/technicalpickles/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/thor-0.19.4/lib/thor/invocation.rb:133:in `map'
	from /Users/technicalpickles/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/thor-0.19.4/lib/thor/invocation.rb:133:in `invoke_all'
	from /Users/technicalpickles/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/thor-0.19.4/lib/thor/group.rb:232:in `dispatch'
	from /Users/technicalpickles/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/thor-0.19.4/lib/thor/base.rb:444:in `start'
	from /Users/technicalpickles/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/railties-5.1.2/lib/rails/commands/application/application_command.rb:24:in `perform'
	from /Users/technicalpickles/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/thor-0.19.4/lib/thor/command.rb:27:in `run'
	from /Users/technicalpickles/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/thor-0.19.4/lib/thor/invocation.rb:126:in `invoke_command'
	from /Users/technicalpickles/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/thor-0.19.4/lib/thor.rb:369:in `dispatch'
	from /Users/technicalpickles/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/railties-5.1.2/lib/rails/command/base.rb:63:in `perform'
	from /Users/technicalpickles/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/railties-5.1.2/lib/rails/command.rb:44:in `invoke'
	from /Users/technicalpickles/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/railties-5.1.2/lib/rails/cli.rb:16:in `<top (required)>'
	from /Users/technicalpickles/.rbenv/versions/2.4.1/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:68:in `require'
	from /Users/technicalpickles/.rbenv/versions/2.4.1/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:68:in `require'
	from /Users/technicalpickles/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/railties-5.1.2/exe/rails:9:in `<top (required)>'
	from /Users/technicalpickles/.rbenv/versions/2.4.1/bin/rails:22:in `load'
	from /Users/technicalpickles/.rbenv/versions/2.4.1/bin/rails:22:in `<main>'

Clearly a developer error, since most uses of this require the use of :after to indicate where to insert the content. It looks like :before or :after are required, so if there is neither, that should be an error.

Rails is using the most recent thor, 0.19.4, and the same code seems to be in master.

@enigmatt-pl
Copy link

This branch fixes it, unless you meant something else?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants