Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/elixir/lib/exception.ex
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ defmodule Exception do
iex> Exception.format_mfa Foo, :bar, []
"Foo.bar()"
iex> Exception.format_mfa nil, :bar, []
"bar()"
"nil.bar()"
"""
def format_mfa(module, fun, arity) do
Expand All @@ -295,7 +295,6 @@ defmodule Exception do
end
end

defp format_module(nil), do: ""
defp format_module(mod), do: "#{inspect mod}."

@doc """
Expand Down
6 changes: 4 additions & 2 deletions lib/elixir/test/elixir/exception_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ defmodule Kernel.ExceptionTest do
assert Exception.format_mfa(Foo, nil, 1) == "Foo.nil/1"
assert Exception.format_mfa(Foo, :bar, 1) == "Foo.bar/1"
assert Exception.format_mfa(Foo, :bar, []) == "Foo.bar()"
assert Exception.format_mfa(nil, :bar, []) == "nil.bar()"
assert Exception.format_mfa(:foo, :bar, [1, 2]) == ":foo.bar(1, 2)"
assert Exception.format_mfa(Foo, :"bar baz", 1) == "Foo.\"bar baz\"/1"
end
Expand All @@ -76,6 +77,7 @@ defmodule Kernel.ExceptionTest do
test :undefined_function_message do
assert UndefinedFunctionError.new.message == "undefined function"
assert UndefinedFunctionError.new(module: Foo, function: :bar, arity: 1).message == "undefined function: Foo.bar/1"
assert UndefinedFunctionError.new(module: nil, function: :bar, arity: 0).message == "undefined function: nil.bar/0"
end

test :function_clause_message do
Expand All @@ -91,13 +93,13 @@ defmodule Kernel.ExceptionTest do
stacktrace =
try do
raise "a"
rescue _ ->
rescue _ ->
[top|_] = System.stacktrace
top
end
file = to_char_list(__FILE__)
assert {Kernel.ExceptionTest, :test_raise_preserves_the_stacktrace, _,
[file: ^file, line: 93]} = stacktrace # line is sensitive
[file: ^file, line: 95]} = stacktrace # line is sensitive
end

defp empty_tuple, do: {}
Expand Down
11 changes: 10 additions & 1 deletion lib/iex/lib/iex/evaluator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,22 @@ defmodule IEx.Evaluator do
end

defp normalize_exception(:undef, [{ IEx.Helpers, fun, arity, _ }|t]) do
{ UndefinedFunctionError[function: fun, arity: arity], t }
{ RuntimeError[message: "undefined function: #{format_function(fun, arity)}"], t }
end

defp normalize_exception(exception, stacktrace) do
{ Exception.normalize(:error, exception), stacktrace }
end

defp format_function(fun, arity) do
cond do
is_list(arity) ->
"#{fun}/#{Enum.count(arity)}"
true ->
"#{fun}/#{arity}"
end
end

defp print_stacktrace(trace, callback) do
try do
io_error callback.()
Expand Down
10 changes: 5 additions & 5 deletions lib/iex/test/iex/helpers_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ defmodule IEx.HelpersTest do

test "import_file helper" do
with_file "dot-iex", "variable = :hello\nimport IO", fn ->
assert "** (UndefinedFunctionError) undefined function: variable()" <> _
assert "** (RuntimeError) undefined function: variable/0" <> _
= capture_iex("variable")
assert "** (UndefinedFunctionError) undefined function: puts(\"hi\")" <> _
assert "** (RuntimeError) undefined function: puts/1" <> _
= capture_iex("puts \"hi\"")

assert capture_iex("import_file \"dot-iex\"\nvariable\nputs \"hi\"")
Expand All @@ -167,11 +167,11 @@ defmodule IEx.HelpersTest do
dot_1 = "variable = :hello\nimport IO"

with_file ["dot-iex", "dot-iex-1"], [dot, dot_1], fn ->
assert "** (UndefinedFunctionError) undefined function: parent()" <> _
assert "** (RuntimeError) undefined function: parent/0" <> _
= capture_iex("parent")
assert "** (UndefinedFunctionError) undefined function: variable()" <> _
assert "** (RuntimeError) undefined function: variable/0" <> _
= capture_iex("variable")
assert "** (UndefinedFunctionError) undefined function: puts(\"hi\")" <> _
assert "** (RuntimeError) undefined function: puts/1" <> _
= capture_iex("puts \"hi\"")

assert capture_iex("import_file \"dot-iex\"\nvariable\nputs \"hi\"\nparent")
Expand Down
8 changes: 7 additions & 1 deletion lib/iex/test/iex/interaction_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,16 @@ defmodule IEx.InteractionTest do
assert capture_iex("if true do ) false end") =~ "** (SyntaxError) iex:1: \"do\" starting at"
end

test "undefined function" do
assert "** (RuntimeError) undefined function: format/0" <> _ = capture_iex("format")
assert "** (RuntimeError) undefined function: with_one/1" <> _ = capture_iex("with_one(22)")
assert "** (RuntimeError) undefined function: many/3" <> _ = capture_iex("many(:ok, 22, \"hi\")")
end

## .iex file loading

test "no .iex" do
assert "** (UndefinedFunctionError) undefined function: my_variable()" <> _ = capture_iex("my_variable")
assert "** (RuntimeError) undefined function: my_variable/0" <> _ = capture_iex("my_variable")
end

test ".iex" do
Expand Down