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

Add descriptive message for unexpected DSL exceptions #913

Merged
merged 1 commit into from Apr 29, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/tapioca/dsl/pipeline.rb
Expand Up @@ -152,6 +152,9 @@ def rbi_for_constant(constant)

compiler = compiler_class.new(self, file.root, constant)
compiler.decorate
rescue
$stderr.puts("Error: `#{compiler_class.name}` failed to generate RBI for `#{constant}`")
raise # This is an unexpected error, so re-raise it
end

return if file.root.empty?
Expand Down
36 changes: 36 additions & 0 deletions spec/tapioca/cli/dsl_spec.rb
Expand Up @@ -1148,6 +1148,42 @@ class Image
assert_project_file_exist("sorbet/rbi/dsl/job.rbi")
assert_project_file_exist("sorbet/rbi/dsl/image.rbi")
end

it "shows a helpful error message when unexpected errors occur" do
@project.write("lib/post.rb", <<~RB)
class Post
end
RB

@project.write("lib/compilers/post_compiler_that_raises.rb", <<~RB)
require "post"
class PostCompilerThatRaises < Tapioca::Dsl::Compiler
def decorate
raise "Some unexpected error happened"
end
def self.gather_constants
[::Post]
end
end
RB

result = @project.tapioca("dsl")

assert_equal(<<~OUT, result.out)
Loading Rails application... Done
Loading DSL compiler classes... Done
Compiling DSL RBI files...
OUT

assert_includes(result.err, "Error: `PostCompilerThatRaises` failed to generate RBI for `Post`")
assert_includes(result.err, "Some unexpected error happened")

refute_project_file_exist("sorbet/rbi/dsl/post.rbi")
refute_success_status(result)
end
end

describe "verify" do
Expand Down