From d043718be8026b032a7333e9db616093ef288c87 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sat, 16 Sep 2023 09:42:52 +0200 Subject: [PATCH] Adds a couple of code comments --- lib/zeitwerk/loader/callbacks.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/zeitwerk/loader/callbacks.rb b/lib/zeitwerk/loader/callbacks.rb index 17b97ce..3fadbd4 100644 --- a/lib/zeitwerk/loader/callbacks.rb +++ b/lib/zeitwerk/loader/callbacks.rb @@ -20,8 +20,16 @@ def on_file_autoloaded(file) else msg = "expected file #{file} to define constant #{cpath}, but didn't" log(msg) if logger + + # Ruby still keeps the autoload defined, but we remove it because the + # contract in Zeitwerk is more strict. crem(*cref) + + # Since the expected constant was not defined, there is nothing to unload. + # However, if the exception is rescued and reloading is enabled, we still + # need to deleted the file from $LOADED_FEATURES. to_unload[cpath] = [file, cref] if reloading_enabled? + raise Zeitwerk::NameError.new(msg, cref.last) end end