Skip to content

Commit

Permalink
Report Rails load errors and continue generating
Browse files Browse the repository at this point in the history
  • Loading branch information
KaanOzkan committed Aug 9, 2022
1 parent 1b9139d commit cd3fd05
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/tapioca/loaders/loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,17 @@ def load_rails_application(environment_load: false, eager_load: false)
silence_deprecations

if environment_load
safe_require("./config/environment")
require "./config/environment"
else
safe_require("./config/application")
require "./config/application"
end

eager_load_rails_app if eager_load
rescue LoadError, StandardError => e
say("Tapioca attempted to load the Rails application after encountering a `config/application.rb` file, " \
"but it failed. If your application uses Rails please ensure it can be loaded correctly before generating " \
"RBIs.\n#{e}", :yellow)
say("Continuing RBI generation without loading the Rails application.")
end

sig { void }
Expand Down
29 changes: 29 additions & 0 deletions spec/tapioca/cli/dsl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1273,6 +1273,35 @@ def saved_change_to_reviewer?; end

assert_success_status(result)
end

it "output errors when rails application cannot be loaded" do
@project.write("config/application.rb", <<~RB)
require "rails"
module Test
class Application < Rails::Application
raise "Error during application loading"
end
end
RB

@project.require_real_gem("rails")
@project.bundle_install
res = @project.tapioca("dsl")

out = "Tapioca attempted to load the Rails application after encountering a `config/application.rb` file, " \
"but it failed. If your application uses Rails please ensure it can be loaded correctly before " \
"generating RBIs."
assert_includes(res.out, out)
assert_includes(res.out, <<~OUT)
Error during application loading
Continuing RBI generation without loading the Rails application.
Done
Loading DSL compiler classes... Done
Compiling DSL RBI files...
OUT
assert_success_status(res)
end
end

describe "verify" do
Expand Down

0 comments on commit cd3fd05

Please sign in to comment.