Skip to content

Commit a73235a

Browse files
author
José Valim
committed
Merge pull request #1875 from pragdave/iex-c-error
Catch attempts to compile missing files in iex and give slightly tidier error messages
2 parents fd57b5d + 718b111 commit a73235a

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

lib/iex/lib/iex/helpers.ex

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,16 @@ defmodule IEx.Helpers do
6969
raise ArgumentError, message: "expected a binary or a list of binaries as argument"
7070
end
7171

72-
{ erls, exs } = Enum.partition(files, &String.ends_with?(&1, ".erl"))
72+
{ found, not_found } = Enum.map(files, &Path.join(path, &1)) |> Enum.partition(&File.exists?/1)
73+
74+
unless Enum.empty?(not_found) do
75+
IO.puts IEx.color(:eval_error, %s[Cannot find #{Enum.join(not_found, ", ")}])
76+
unless Enum.empty?(found) do
77+
IO.puts IEx.color(:eval_info, "(remaining file(s) will be compiled)")
78+
end
79+
end
80+
81+
{ erls, exs } = Enum.partition(found, &String.ends_with?(&1, ".erl"))
7382

7483
modules = Enum.map(erls, fn(source) ->
7584
{ module, binary } = compile_erlang(source)

lib/iex/test/iex/helpers_test.exs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,23 @@ defmodule IEx.HelpersTest do
251251
cleanup_modules([:sample])
252252
end
253253

254+
255+
test "c helper skips unknown files" do
256+
assert_raise UndefinedFunctionError, "undefined function: :sample.hello/0", fn ->
257+
:sample.hello
258+
end
259+
260+
filenames = ["sample.erl", "not_found.ex", "sample2.ex"]
261+
with_file filenames, [erlang_module_code, "", another_test_module], fn ->
262+
assert c(filenames) |> Enum.sort == [Sample2, :sample]
263+
assert :sample.hello == :world
264+
assert Sample2.hello == :world
265+
end
266+
after
267+
cleanup_modules([:sample, Sample2])
268+
end
269+
270+
254271
test "l helper" do
255272
assert_raise UndefinedFunctionError, "undefined function: Sample.run/0", fn ->
256273
Sample.run

0 commit comments

Comments
 (0)