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

Fix error when trying to display error message #11742

Merged

Commits on Mar 29, 2023

  1. Fix error when trying to display error message

    When RuboCop errors, it prints a message that includes the issue tracker
    URL. It pulls this URL from the gem spec metadata.
    
    Relying on the gem spec can cause problems in bundler standalone mode,
    where everything is set up by the standalone file and `Gem.loaded_specs`
    is not populated with the bundled gems.
    
    ```
    $ bundle init
    $ bundle add rubocop --skip-install
    $ bundle install --standalone
    $ ruby -r ./bundle/bundler/setup.rb -e 'require "rubocop"; Gem.loaded_specs["bundler"].metadata['bug_tracker_uri']'
    undefined method `metadata' for nil:NilClass (NoMethodError)
    ```
    
    This means that if RuboCop errors, instead of a helpful error message we
    get a cryptic error that masks the underlying problem. We've seen this a
    number of times at GitHub (although mostly when developing our own
    internal cops and not from bugs in RuboCop itself).
    
    This commit makes the error reporting more resilient by skipping the
    issue tracker URL when the rubocop spec is unavailable. Leaving out the
    URL in this case seems OK to me, since it's basically falling back to
    the error message before rubocop@ef74a18.
    Hard-coding the URL is another option, although there's some risk of it
    falling out of sync some day.
    
    I didn't find any existing test coverage for this code (perhaps because
    it only gets run if something else is broken), so I haven't added any
    additional coverage here.
    composerinteralia committed Mar 29, 2023
    Configuration menu
    Copy the full SHA
    d6bc76a View commit details
    Browse the repository at this point in the history