diff --git a/CHANGELOG.md b/CHANGELOG.md index 55baa07c..bf8dcaa3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,14 +4,14 @@ * Controlled errors in a couple of situations: - - Attempting to eager load or reload before invoking `setup` now raises - `Zeitwerk::SetupRequired`. + - Attempting to eager load or reload without previously invoking `setup` now + raises `Zeitwerk::SetupRequired`. - The method `Zeitwerk::Loader#push_dir` raises `Zeitwerk::Error` if it gets an anonymous custom namespace. These should be backwards compatible, because they raise in circumstances that - didn't work anyway. + didn't work anyway. The goal here is to raise a meaningful error upfront. * Enforcement of private interfaces continues with another gradual patch. diff --git a/README.md b/README.md index 7242a494..4f8eb248 100644 --- a/README.md +++ b/README.md @@ -601,7 +601,7 @@ loader.reload There is no way to undo this, either you want to reload or you don't. -Enabling reloading after setup raises `Zeitwerk::Error`. Attempting to reload without having it enabled raises `Zeitwerk::ReloadingDisabledError`. Attempting to reload before calling `setup` raises `Zeitwerk::SetupRequired`. +Enabling reloading after setup raises `Zeitwerk::Error`. Attempting to reload without having it enabled raises `Zeitwerk::ReloadingDisabledError`. Attempting to reload without previously calling `setup` raises `Zeitwerk::SetupRequired`. Generally speaking, reloading is useful while developing running services like web applications. Gems that implement regular libraries, so to speak, or services running in testing or production environments, won't normally have a use case for reloading. If reloading is not enabled, Zeitwerk is able to use less memory. diff --git a/lib/zeitwerk/loader.rb b/lib/zeitwerk/loader.rb index 51d143df..2973f0b2 100644 --- a/lib/zeitwerk/loader.rb +++ b/lib/zeitwerk/loader.rb @@ -140,7 +140,7 @@ def setup # @sig () -> void def unload mutex.synchronize do - raise Zeitwerk::SetupRequired unless @setup + raise SetupRequired unless @setup # We are going to keep track of the files that were required by our # autoloads to later remove them from $LOADED_FEATURES, thus making them @@ -218,7 +218,7 @@ def unload # @sig () -> void def reload raise ReloadingDisabledError unless reloading_enabled? - raise Zeitwerk::SetupRequired unless @setup + raise SetupRequired unless @setup unload recompute_ignored_paths @@ -294,7 +294,7 @@ def eager_load_all Registry.loaders.each do |loader| begin loader.eager_load - rescue Zeitwerk::SetupRequired + rescue SetupRequired # This is fine, we eager load what can be eager loaded. end end @@ -308,7 +308,7 @@ def eager_load_namespace(mod) Registry.loaders.each do |loader| begin loader.eager_load_namespace(mod) - rescue Zeitwerk::SetupRequired + rescue SetupRequired # This is fine, we eager load what can be eager loaded. end end