improves the reloading disabled error message

The original message from Zeitwerk is "can't reload, please call
loader.enable_reloading before setup (Zeitwerk::Error)", which is not
very informative for Rails programmers.

Rails should err with a message worded in terms of its interface.
This commit is contained in:
Xavier Noria 2019-04-11 22:43:45 +02:00
parent 23392eff9f
commit 7b6b10542d
4 changed files with 17 additions and 4 deletions

View File

@ -71,7 +71,7 @@ PATH
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
zeitwerk (~> 2.1)
zeitwerk (~> 2.1, >= 2.1.2)
rails (6.0.0.beta3)
actioncable (= 6.0.0.beta3)
actionmailbox (= 6.0.0.beta3)
@ -526,7 +526,7 @@ GEM
websocket-extensions (0.1.3)
xpath (3.2.0)
nokogiri (~> 1.8)
zeitwerk (2.1.0)
zeitwerk (2.1.2)
PLATFORMS
java

View File

@ -34,5 +34,5 @@ Gem::Specification.new do |s|
s.add_dependency "tzinfo", "~> 1.1"
s.add_dependency "minitest", "~> 5.1"
s.add_dependency "concurrent-ruby", "~> 1.0", ">= 1.0.2"
s.add_dependency "zeitwerk", "~> 2.1"
s.add_dependency "zeitwerk", "~> 2.1", ">= 2.1.2"
end

View File

@ -9,7 +9,11 @@ module ActiveSupport
module Decorations
def clear
Dependencies.unload_interlock do
Rails.autoloaders.main.reload
begin
Rails.autoloaders.main.reload
rescue Zeitwerk::ReloadingDisabledError
raise "reloading is disabled because config.cache_classes is true"
end
end
end

View File

@ -156,6 +156,15 @@ class ZeitwerkIntegrationTest < ActiveSupport::TestCase
assert_not Rails.autoloaders.once.reloading_enabled?
end
test "reloading raises if config.cache_classes is true" do
boot("production")
e = assert_raises(StandardError) do
deps.clear
end
assert_equal "reloading is disabled because config.cache_classes is true", e.message
end
test "eager loading loads code in engines" do
$test_blog_engine_eager_loaded = false