Skip to content

Commit

Permalink
Show friendly error when plugin is missing (#77)
Browse files Browse the repository at this point in the history
If you try to run a task but the namespace of the task is not
recognized, tomo will now helpfully suggest that you may need to load
the plugin that defines that namespace. E.g.

```
$ tomo run sidekiq:setup
tomo run v0.12.0

  ERROR: sidekiq:setup is not a recognized task.
  To see a list of all available tasks, run tomo tasks.

  Did you forget to install the sidekiq plugin?
```
  • Loading branch information
mattbrictson authored Nov 17, 2019
1 parent c6a1593 commit 1f1605f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
19 changes: 16 additions & 3 deletions lib/tomo/runtime/unknown_task_error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,27 @@ def to_console
To see a list of all available tasks, run #{blue('tomo tasks')}.
ERROR

# TODO: suggest "did you forget to add the <abc> plugin?"
sugg = spelling_suggestion || missing_plugin_suggestion
error << sugg if sugg
error
end

private

def spelling_suggestion
sugg = Error::Suggestions.new(
dictionary: known_tasks,
word: unknown_task
)
error << sugg.to_console if sugg.any?
error
sugg.to_console if sugg.any?
end

def missing_plugin_suggestion
unknown_plugin = unknown_task[/\A(.+?):/, 1]
known_plugins = known_tasks.map { |t| t.split(":").first }.uniq
return if unknown_plugin.nil? || known_plugins.include?(unknown_plugin)

"\nDid you forget to install the #{blue(unknown_plugin)} plugin?"
end
end
end
Expand Down
6 changes: 6 additions & 0 deletions test/tomo/cli_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ def test_execute_task_with_implicit_run_command
assert_match "Simulated bundler:install", @tester.stdout
end

def test_suggests_installing_missing_plugin
@tester.run "init"
@tester.run "foo:setup", raise_on_error: false
assert_match(/did you forget to install the foo plugin/i, @tester.stderr)
end

def test_prints_error_when_config_has_syntax_error
@tester.in_temp_dir do
FileUtils.mkdir_p(".tomo")
Expand Down

0 comments on commit 1f1605f

Please sign in to comment.