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

Rubocop binstubs issue causes failures on Windows #51618

Open
mohits opened this issue Apr 20, 2024 · 2 comments
Open

Rubocop binstubs issue causes failures on Windows #51618

mohits opened this issue Apr 20, 2024 · 2 comments

Comments

@mohits
Copy link
Contributor

mohits commented Apr 20, 2024

Steps to reproduce

After setting up a new application with Rails main, create a controller in the empty application.

$ ruby bin\rails g controller home welcome

Expected behavior

The generate command should complete successfully without any errors from Rubocop.

$ ruby bin\rails g controller home welcome --force
   identical  app/controllers/home_controller.rb
       route  get "home/welcome"
      invoke  erb
       exist    app/views/home
   identical    app/views/home/welcome.html.erb
      invoke  helper
   identical    app/helpers/home_helper.rb
Inspecting 2 files
..

Actual behavior

The command completes but ends with an error from Rubocop.

$ ruby bin\rails g controller home welcome
      create  app/controllers/home_controller.rb
       route  get "home/welcome"
      invoke  erb
      create    app/views/home
      create    app/views/home/welcome.html.erb
      invoke  helper
      create    app/helpers/home_helper.rb
D:/Ruby33-x64/lib/ruby/gems/3.3.0/bundler/gems/rails-284baa18c2c6/railties/lib/rails/configuration.rb:138:in `system': Exec format error - bin/rubocop -A --fail-level=E app/controllers/home_controller.rb app/helpers/home_helper.rb (Errno::ENOEXEC)
        from D:/Ruby33-x64/lib/ruby/gems/3.3.0/bundler/gems/rails-284baa18c2c6/railties/lib/rails/configuration.rb:138:in `block in apply_rubocop_autocorrect_after_generate!'
        from D:/Ruby33-x64/lib/ruby/gems/3.3.0/bundler/gems/rails-284baa18c2c6/railties/lib/rails/generators.rb:317:in `block in run_after_generate_callback'
        from D:/Ruby33-x64/lib/ruby/gems/3.3.0/bundler/gems/rails-284baa18c2c6/railties/lib/rails/generators.rb:316:in `each'
        from D:/Ruby33-x64/lib/ruby/gems/3.3.0/bundler/gems/rails-284baa18c2c6/railties/lib/rails/generators.rb:316:in `run_after_generate_callback'
        from D:/Ruby33-x64/lib/ruby/gems/3.3.0/bundler/gems/rails-284baa18c2c6/railties/lib/rails/generators.rb:263:in `invoke'
        from D:/Ruby33-x64/lib/ruby/gems/3.3.0/bundler/gems/rails-284baa18c2c6/railties/lib/rails/commands/generate/generate_command.rb:26:in `perform'
        from D:/Ruby33-x64/lib/ruby/gems/3.3.0/gems/thor-1.3.1/lib/thor/command.rb:28:in `run'
        from D:/Ruby33-x64/lib/ruby/gems/3.3.0/gems/thor-1.3.1/lib/thor/invocation.rb:127:in `invoke_command'
        from D:/Ruby33-x64/lib/ruby/gems/3.3.0/bundler/gems/rails-284baa18c2c6/railties/lib/rails/command/base.rb:178:in `invoke_command'
        from D:/Ruby33-x64/lib/ruby/gems/3.3.0/gems/thor-1.3.1/lib/thor.rb:527:in `dispatch'
        from D:/Ruby33-x64/lib/ruby/gems/3.3.0/bundler/gems/rails-284baa18c2c6/railties/lib/rails/command/base.rb:73:in `perform'
        from D:/Ruby33-x64/lib/ruby/gems/3.3.0/bundler/gems/rails-284baa18c2c6/railties/lib/rails/command.rb:71:in `block in invoke'
        from D:/Ruby33-x64/lib/ruby/gems/3.3.0/bundler/gems/rails-284baa18c2c6/railties/lib/rails/command.rb:149:in `with_argv'
        from D:/Ruby33-x64/lib/ruby/gems/3.3.0/bundler/gems/rails-284baa18c2c6/railties/lib/rails/command.rb:69:in `invoke'
        from D:/Ruby33-x64/lib/ruby/gems/3.3.0/bundler/gems/rails-284baa18c2c6/railties/lib/rails/commands.rb:18:in `<main>'
        from D:/Ruby33-x64/lib/ruby/3.3.0/bundled_gems.rb:74:in `require'
        from D:/Ruby33-x64/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require'
        from D:/Ruby33-x64/lib/ruby/gems/3.3.0/gems/bootsnap-1.18.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
        from bin/rails:4:in `<main>'

System configuration

Rails version: 7.2.0-alpha

  remote: https://github.com/rails/rails.git
  revision: 284baa18c2c62abec170b61e285aefbd9604f675
  branch: main

Ruby version: ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x64-mingw-ucrt]

Fix

The issue is fixed by installing binstubs for rubocop (unfortunately, right now, I do not know where the fix would be applied in the Rails codebase).

$ bundle binstubs rubocop --force

If you point me to where it should go, I am happy to open a PR. Else, I'm happy for someone to do this at the correct place. Thanks!

Other Information

Detailed links:

@mohits mohits changed the title Rubocop binstubs issues causes failures on Windows Rubocop binstubs issue causesfailures on Windows Apr 20, 2024
@mohits mohits changed the title Rubocop binstubs issue causesfailures on Windows Rubocop binstubs issue causes failures on Windows Apr 20, 2024
@andyw8
Copy link
Contributor

andyw8 commented May 1, 2024

I believe the correct fix is just to change Rails to run ruby bin/rubocop instead of bin/rubocop.

@andyw8
Copy link
Contributor

andyw8 commented May 1, 2024

system("bin/rubocop -A --fail-level=E #{parsable_files.shelljoin}", exception: true)

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

No branches or pull requests

2 participants