From 49d97aa3a4ba6ad7071858aedcf4774ac37f7d5b Mon Sep 17 00:00:00 2001 From: Alex Rocha Date: Mon, 9 Dec 2024 20:49:53 -0800 Subject: [PATCH] Handle missing gems gracefully in tapioca gem command --- lib/tapioca/commands/abstract_gem.rb | 2 ++ spec/tapioca/cli/gem_spec.rb | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/lib/tapioca/commands/abstract_gem.rb b/lib/tapioca/commands/abstract_gem.rb index e0cad5c09..6ffcfd5b1 100644 --- a/lib/tapioca/commands/abstract_gem.rb +++ b/lib/tapioca/commands/abstract_gem.rb @@ -84,6 +84,8 @@ def gems_to_generate(gem_names) gem = @bundle.gem(gem_name) if gem.nil? + next say("Warning: Cannot find gem '#{gem_name}', skipping", :yellow) if @lsp_addon + raise Thor::Error, set_color("Error: Cannot find gem '#{gem_name}'", :red) end diff --git a/spec/tapioca/cli/gem_spec.rb b/spec/tapioca/cli/gem_spec.rb index 4e412e6b2..e97adcf7c 100644 --- a/spec/tapioca/cli/gem_spec.rb +++ b/spec/tapioca/cli/gem_spec.rb @@ -824,6 +824,22 @@ class Secret; end assert_success_status(result) end + it "skips missing gems and continues with warning when --lsp_addon is used" do + result = @project.tapioca("gem non_existent_gem --lsp_addon") + + assert_stdout_includes(result, "Warning: Cannot find gem 'non_existent_gem', skipping") + + assert_empty_stderr(result) + assert_success_status(result) + end + + it "fails with error when gem cannot be found" do + result = @project.tapioca("gem non_existent_gem") + + assert_stderr_includes(result, "Error: Cannot find gem 'non_existent_gem'") + refute_success_status(result) + end + it "does not crash when the extras gem is loaded" do foo = mock_gem("foo", "0.0.1") do write!("lib/foo.rb", FOO_RB)