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

Make unprocessable compilers a warning instead of an error #1794

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading