Skip to content

Commit 37054c8

Browse files
author
José Valim
committed
Deprecate Exception.format_entry in favor of Exception.format_stacktrace_entry
1 parent 9751ca7 commit 37054c8

File tree

4 files changed

+34
-27
lines changed

4 files changed

+34
-27
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
* deprecations
3737
* [Code] `Code.eval` is deprecated in favor of `Code.eval_string`
38+
* [Exception] `Exception.format_entry` is deprecated in favor of `Exception.format_stacktrace_entry`
3839
* [ExUnit] `assert left inlist right` is deprecated in favor of `assert left in right`
3940
* [IO] `IO.getb` is deprecated in favor of `IO.getn`
4041
* [List] `List.member?/2` is deprecated in favor of `Enum.member?/2`

lib/elixir/lib/exception.ex

+13-7
Original file line numberDiff line numberDiff line change
@@ -150,33 +150,39 @@ defmodule Exception do
150150
ErlangError[original: other]
151151
end
152152

153+
@doc false
154+
def format_entry(entry, cwd // nil) do
155+
IO.write "[WARNING] Exception.format_stacktrace is deprecated, please use Exception.format_stacktrace_entry instead\n#{Exception.format_stacktrace}"
156+
format_stacktrace_entry(entry, cwd)
157+
end
158+
153159
@doc """
154160
Receives a tuple representing a stacktrace entry and formats it.
155161
The current working directory may be given as argument, which
156162
is used to prettify the stacktrace.
157163
"""
158-
def format_entry(entry, cwd // nil)
164+
def format_stacktrace_entry(entry, cwd // nil)
159165

160166
# From Macro.Env.stacktrace
161-
def format_entry({ module, :__MODULE__, 0, file_line }, cwd) do
167+
def format_stacktrace_entry({ module, :__MODULE__, 0, file_line }, cwd) do
162168
"#{format_file_line(file_line, cwd)}#{inspect module} (module)"
163169
end
164170

165171
# From :elixir_compiler
166-
def format_entry({ _module, :__MODULE__, 2, file_line }, cwd) do
172+
def format_stacktrace_entry({ _module, :__MODULE__, 2, file_line }, cwd) do
167173
"#{format_file_line(file_line, cwd)}(module)"
168174
end
169175

170176
# From :elixir_compiler
171-
def format_entry({ _module, :__FILE__, 2, file_line }, cwd) do
177+
def format_stacktrace_entry({ _module, :__FILE__, 2, file_line }, cwd) do
172178
"#{format_file_line(file_line, cwd)}(file)"
173179
end
174180

175-
def format_entry({module, fun, arity, file_line}, cwd) do
181+
def format_stacktrace_entry({module, fun, arity, file_line}, cwd) do
176182
"#{format_file_line(file_line, cwd)}#{format_module_fun_arity(module, fun, arity)}"
177183
end
178184

179-
def format_entry({fun, arity, file_line}, cwd) do
185+
def format_stacktrace_entry({fun, arity, file_line}, cwd) do
180186
"#{format_file_line(file_line, cwd)}#{format_fun_arity(fun, arity)}"
181187
end
182188

@@ -198,7 +204,7 @@ defmodule Exception do
198204

199205
case trace do
200206
[] -> "\n"
201-
s -> " " <> Enum.map_join(s, "\n ", format_entry(&1)) <> "\n"
207+
s -> " " <> Enum.map_join(s, "\n ", format_stacktrace_entry(&1)) <> "\n"
202208
end
203209
end
204210

lib/elixir/test/elixir/exception_test.exs

+18-18
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,32 @@ defmodule Kernel.ExceptionTest do
1010
refute is_exception(a_list)
1111
end
1212

13-
test :format_entry_with_no_file_or_line do
14-
assert Exception.format_entry({Foo, :bar, [1, 2, 3], []}) == "Foo.bar(1, 2, 3)"
15-
assert Exception.format_entry({Foo, :bar, [], []}) == "Foo.bar()"
16-
assert Exception.format_entry({Foo, :bar, 1, []}) == "Foo.bar/1"
13+
test :format_stacktrace_entry_with_no_file_or_line do
14+
assert Exception.format_stacktrace_entry({Foo, :bar, [1, 2, 3], []}) == "Foo.bar(1, 2, 3)"
15+
assert Exception.format_stacktrace_entry({Foo, :bar, [], []}) == "Foo.bar()"
16+
assert Exception.format_stacktrace_entry({Foo, :bar, 1, []}) == "Foo.bar/1"
1717
end
1818

19-
test :format_entry_with_file_and_line do
20-
assert Exception.format_entry({Foo, :bar, [], [file: 'file.ex', line: 10]}) == "file.ex:10: Foo.bar()"
21-
assert Exception.format_entry({Foo, :bar, [1, 2, 3], [file: 'file.ex', line: 10]}) == "file.ex:10: Foo.bar(1, 2, 3)"
22-
assert Exception.format_entry({Foo, :bar, 1, [file: 'file.ex', line: 10]}) == "file.ex:10: Foo.bar/1"
19+
test :format_stacktrace_entry_with_file_and_line do
20+
assert Exception.format_stacktrace_entry({Foo, :bar, [], [file: 'file.ex', line: 10]}) == "file.ex:10: Foo.bar()"
21+
assert Exception.format_stacktrace_entry({Foo, :bar, [1, 2, 3], [file: 'file.ex', line: 10]}) == "file.ex:10: Foo.bar(1, 2, 3)"
22+
assert Exception.format_stacktrace_entry({Foo, :bar, 1, [file: 'file.ex', line: 10]}) == "file.ex:10: Foo.bar/1"
2323
end
2424

25-
test :format_entry_with_file_and_line_and_cwd do
26-
assert Exception.format_entry({Foo, :bar, [], [file: '/foo/file.ex', line: 10]}, "/foo") == "file.ex:10: Foo.bar()"
25+
test :format_stacktrace_entry_with_file_and_line_and_cwd do
26+
assert Exception.format_stacktrace_entry({Foo, :bar, [], [file: '/foo/file.ex', line: 10]}, "/foo") == "file.ex:10: Foo.bar()"
2727
end
2828

29-
test :format_entry_with_file_no_line do
30-
assert Exception.format_entry({Foo, :bar, [], [file: 'file.ex']}) == "file.ex: Foo.bar()"
31-
assert Exception.format_entry({Foo, :bar, [], [file: 'file.ex', line: 0]}) == "file.ex: Foo.bar()"
32-
assert Exception.format_entry({Foo, :bar, [1, 2, 3], [file: 'file.ex']}) == "file.ex: Foo.bar(1, 2, 3)"
33-
assert Exception.format_entry({Foo, :bar, 1, [file: 'file.ex']}) == "file.ex: Foo.bar/1"
29+
test :format_stacktrace_entry_with_file_no_line do
30+
assert Exception.format_stacktrace_entry({Foo, :bar, [], [file: 'file.ex']}) == "file.ex: Foo.bar()"
31+
assert Exception.format_stacktrace_entry({Foo, :bar, [], [file: 'file.ex', line: 0]}) == "file.ex: Foo.bar()"
32+
assert Exception.format_stacktrace_entry({Foo, :bar, [1, 2, 3], [file: 'file.ex']}) == "file.ex: Foo.bar(1, 2, 3)"
33+
assert Exception.format_stacktrace_entry({Foo, :bar, 1, [file: 'file.ex']}) == "file.ex: Foo.bar/1"
3434
end
3535

36-
test :format_entry_with_fun do
37-
assert Exception.format_entry({fn(x) -> x end, [1], []}) =~ %r"\(1\)"
38-
assert Exception.format_entry({fn(x, y) -> { x, y } end, 2, []}) =~ %r"/2"
36+
test :format_stacktrace_entry_with_fun do
37+
assert Exception.format_stacktrace_entry({fn(x) -> x end, [1], []}) =~ %r"\(1\)"
38+
assert Exception.format_stacktrace_entry({fn(x, y) -> { x, y } end, 2, []}) =~ %r"/2"
3939
end
4040

4141
test :format_module_function_arity do

lib/ex_unit/lib/ex_unit/cli_formatter.ex

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ defmodule ExUnit.CLIFormatter do
88
@timeout 30_000
99
use GenServer.Behaviour
1010

11-
import Exception, only: [format_entry: 2]
11+
import Exception, only: [format_stacktrace_entry: 2]
1212
defrecord Config, counter: 0, test_failures: [], case_failures: []
1313

1414
## Behaviour
@@ -157,7 +157,7 @@ defmodule ExUnit.CLIFormatter do
157157

158158
defp print_stacktrace(stacktrace, _case, _test, cwd) do
159159
IO.puts location_info "stacktrace:"
160-
Enum.each stacktrace, fn(s) -> IO.puts stacktrace_info format_entry(s, cwd) end
160+
Enum.each stacktrace, fn(s) -> IO.puts stacktrace_info format_stacktrace_entry(s, cwd) end
161161
end
162162

163163
defp print_time(run_us, nil) do

0 commit comments

Comments
 (0)