Skip to content

Commit 224c259

Browse files
koicbbatsov
authored andcommitted
Make plugin load error messages more user-friendly
Users who encounter plugin load errors are usually those who have misconfigured the plugin, rather than the plugin developers. ## Before The previous error message was more geared towards plugin developers. ```console $ bundle exec rubocop lib/rubocop.rb Error: Failed loading plugin `rubocop-performance` because we couldn't determine the corresponding plugin class to instantiate. First, try upgrading it. If the issue persists, please check with the developer regarding the following points. RuboCop plugin class names must either be: - If the plugin is a gem, defined in the gemspec as `default_lint_roller_plugin' spec.metadata['default_lint_roller_plugin'] = 'MyModule::Plugin' - Set in YAML as `plugin_class_name'; example: plugins: - incomplete: require_path: my_module/plugin plugin_class_name: "MyModule::Plugin" ``` This error message might only confuse the user. ## After This PR adjusts the message to guide users on the actions they should take when they see the error. ```console $ bundle exec rubocop path/to/file.rb Error: Failed to load plugin `rubocop-performance` because the corresponding plugin class could not be determined for instantiation. Try upgrading it first (e.g., `bundle update rubocop-performance`). If `rubocop-performance` is not yet a plugin, use `require: rubocop-performance` instead of `plugins: `rubocop-performance` in your configuration. For further assistance, check with the developer regarding the following points: https://docs.rubocop.org/rubocop/plugin_migration_guide.html ``` In most cases, this load error occurs because an extension cop doesn't support plugin system yet, `.rubocop.yml` contains `plugins: rubocop-foo`. In this situation, the user has two options: run `bundle update`, or if that doesn't resolve the issue, update `.rubocop.yml` to use `require: rubocop-foo` instead. If contacting the developer is necessary, the migration guide included in this message may be helpful.
1 parent 272303d commit 224c259

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

lib/rubocop/plugin/load_error.rb

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,12 @@ def initialize(plugin_name)
1313

1414
def message
1515
<<~MESSAGE
16-
Failed loading plugin `#{@plugin_name}` because we couldn't determine the corresponding plugin class to instantiate.
17-
First, try upgrading it. If the issue persists, please check with the developer regarding the following points.
16+
Failed to load plugin `#{@plugin_name}` because the corresponding plugin class could not be determined for instantiation.
17+
Try upgrading it first (e.g., `bundle update #{@plugin_name}`).
18+
If `#{@plugin_name}` is not yet a plugin, use `require: #{@plugin_name}` instead of `plugins: `#{@plugin_name}` in your configuration.
1819
19-
RuboCop plugin class names must either be:
20-
21-
- If the plugin is a gem, defined in the gemspec as `default_lint_roller_plugin'
22-
23-
spec.metadata['default_lint_roller_plugin'] = 'MyModule::Plugin'
24-
25-
- Set in YAML as `plugin_class_name'; example:
26-
27-
plugins:
28-
- incomplete:
29-
require_path: my_module/plugin
30-
plugin_class_name: "MyModule::Plugin"
20+
For further assistance, check with the developer regarding the following points:
21+
https://docs.rubocop.org/rubocop/plugin_migration_guide.html
3122
MESSAGE
3223
end
3324
end

0 commit comments

Comments
 (0)