Skip to content

Commit

Permalink
Merge pull request #913 from Shopify/uk-better-exceptions
Browse files Browse the repository at this point in the history
Add descriptive message for unexpected DSL exceptions
  • Loading branch information
paracycle committed Apr 29, 2022
2 parents 518adff + 58965e4 commit 03619fb
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
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

0 comments on commit 03619fb

Please sign in to comment.