Skip to content

Commit

Permalink
Merge pull request #1794 from Shopify/uk-warn-for-unprocessable-compi…
Browse files Browse the repository at this point in the history
…lers

Make unprocessable compilers a warning instead of an error
  • Loading branch information
paracycle authored Feb 12, 2024
2 parents eb57467 + 039632d commit cf7a580
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 15 deletions.
5 changes: 3 additions & 2 deletions lib/tapioca/commands/abstract_dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,11 @@ def constantize_compilers(compiler_names)

unless unprocessable_compilers.empty?
message = unprocessable_compilers.map do |name, _|
set_color("Error: Cannot find compiler '#{name}'", :red)
set_color("Warning: Cannot find compiler '#{name}'", :yellow)
end.join("\n")

raise Thor::Error, message
say(message)
say("")
end

T.cast(compiler_map.values, T::Array[T.class_of(Tapioca::Dsl::Compiler)])
Expand Down
60 changes: 47 additions & 13 deletions spec/tapioca/cli/dsl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1163,22 +1163,39 @@ module FooModule; end
assert_success_status(result)
end

it "errors if there are no matching compilers" do
result = @project.tapioca("dsl --only NonexistentCompiler")
it "warns if there are no matching compilers but continues processing" do
@project.write!("lib/post.rb", <<~RB)
require "smart_properties"
class Post
include SmartProperties
property :title, accepts: String
end
RB

result = @project.tapioca("dsl --only SmartProperties NonexistentCompiler")

assert_equal(<<~OUT, result.out)
Loading DSL extension classes... Done
Loading Rails application... Done
Loading DSL compiler classes... Done
Compiling DSL RBI files...
OUT
Warning: Cannot find compiler 'NonexistentCompiler'
assert_equal(<<~ERROR, result.err)
Error: Cannot find compiler 'NonexistentCompiler'
ERROR
create sorbet/rbi/dsl/post.rbi
refute_success_status(result)
Done
Checking generated RBI files... Done
No errors found
All operations performed in working directory.
Please review changes and commit them.
OUT

assert_empty_stderr(result)
assert_success_status(result)
end

it "must respect `exclude` option" do
Expand Down Expand Up @@ -1252,7 +1269,16 @@ def self.gather_constants
assert_success_status(result)
end

it "errors if there are no matching `exclude` compilers" do
it "warns if there are no matching `exclude` compilers but continues processing" do
@project.write!("lib/post.rb", <<~RB)
require "smart_properties"
class Post
include SmartProperties
property :title, accepts: String
end
RB

result = @project.tapioca("dsl --exclude NonexistentCompiler")

assert_equal(<<~OUT, result.out)
Expand All @@ -1261,13 +1287,21 @@ def self.gather_constants
Loading DSL compiler classes... Done
Compiling DSL RBI files...
OUT
Warning: Cannot find compiler 'NonexistentCompiler'
assert_equal(<<~ERROR, result.err)
Error: Cannot find compiler 'NonexistentCompiler'
ERROR
create sorbet/rbi/dsl/post.rbi
refute_success_status(result)
Done
Checking generated RBI files... Done
No errors found
All operations performed in working directory.
Please review changes and commit them.
OUT

assert_empty_stderr(result)
assert_success_status(result)
end

it "must warn about reloaded constants and process only the newest one" do
Expand Down

0 comments on commit cf7a580

Please sign in to comment.