Skip to content

Commit

Permalink
Further revise the Zeitwerk::NameError message
Browse files Browse the repository at this point in the history
While it could be argued that the previous version
read easily for non-top-level namespaces, let's
have a sentence structure that matches the one for
top-level namespaces.
  • Loading branch information
fxn committed Apr 2, 2024
1 parent 3d43c2f commit 4082b45
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/zeitwerk/loader/callbacks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ module Zeitwerk::Loader::Callbacks
to_unload[cpath] = [file, cref] if reloading_enabled?
run_on_load_callbacks(cpath, cget(*cref), file) unless on_load_callbacks.empty?
else
namespace = cref[0] == Object ? "top-level namespace" : "namespace #{real_mod_name(cref[0])}"
msg = "expected #{file} to define #{cref[1]} in the #{namespace}"
namespace = cref[0] == Object ? "top-level" : real_mod_name(cref[0])
msg = "expected #{file} to define #{cref[1]} in the #{namespace} namespace"
log(msg) if logger

# Ruby still keeps the autoload defined, but we remove it because the
Expand Down
6 changes: 3 additions & 3 deletions test/lib/zeitwerk/test_exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def assert_error_message(message, error)
with_setup(files) do
typo_rb = File.expand_path("m/typo.rb")
error = assert_raises(Zeitwerk::NameError) { M::Typo }
assert_error_message "expected #{typo_rb} to define Typo in the namespace M", error
assert_error_message "expected #{typo_rb} to define Typo in the M namespace", error
assert_equal :Typo, error.name
end
end
Expand All @@ -49,7 +49,7 @@ def assert_error_message(message, error)
with_setup(files) do
x_rb = File.expand_path("m/x.rb")
error = assert_raises(Zeitwerk::NameError) { loader.eager_load }
assert_error_message "expected #{x_rb} to define X in the namespace M", error
assert_error_message "expected #{x_rb} to define X in the M namespace", error
assert_equal :X, error.name
end
end
Expand All @@ -64,7 +64,7 @@ def assert_error_message(message, error)
with_setup(files) do
cli_x_rb = File.expand_path("cli/x.rb")
error = assert_raises(Zeitwerk::NameError) { loader.eager_load }
assert_error_message "expected #{cli_x_rb} to define X in the namespace Cli", error
assert_error_message "expected #{cli_x_rb} to define X in the Cli namespace", error
assert_equal :X, error.name
end
end
Expand Down

0 comments on commit 4082b45

Please sign in to comment.