Skip to content

Commit ddd4afb

Browse files
author
Ricardo de Cillo
committed
Improve error message for IEx.Helpers.r when module does not exist.
Before this commit, when trying to reload an unloaded module, the user would see an error like: iex(1)> r InexistentModule ** (UndefinedFunctionError) undefined function: InexistentModule.module_info/1 InexistentModule.module_info(:compile) lib/iex/lib/iex/helpers.ex:352: IEx.Helpers.source/1 lib/iex/lib/iex/helpers.ex:311: IEx.Helpers.do_r/1 lib/iex/lib/iex/helpers.ex:304: IEx.Helpers.r/1 After this commit, the user should see iex(1)> r InexistentModule ** (ArgumentError) Unloaded module Elixir.InexistentModule. Try loading the module's beam file with `IEx.Helpers.l\1` lib/iex/lib/iex/helpers.ex:312: IEx.Helpers.do_r/1 lib/iex/lib/iex/helpers.ex:304: IEx.Helpers.r/1 Which is more informative.
1 parent 99b1d9b commit ddd4afb

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

lib/iex/lib/iex/helpers.ex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,10 @@ defmodule IEx.Helpers do
308308
end
309309

310310
defp do_r(module) do
311+
unless :code.is_loaded(module) do
312+
raise ArgumentError, message: "Unloaded module #{module}. Try loading the module's beam file with `IEx.Helpers.l\\1`"
313+
end
314+
311315
source = source(module)
312316
cond do
313317
source == nil ->

lib/iex/test/iex/helpers_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ defmodule IEx.HelpersTest do
305305
end
306306

307307
test "r helper unavailable" do
308-
assert_raise UndefinedFunctionError, "undefined function: :non_existent_module.module_info/1", fn ->
308+
assert_raise ArgumentError, "Unloaded module non_existent_module. Try loading the module's beam file with `IEx.Helpers.l\\1`", fn ->
309309
r :non_existent_module
310310
end
311311
end

0 commit comments

Comments
 (0)