Skip to content

Commit b6e7fa2

Browse files
author
José Valim
committed
Expand reraise/2 without code injection similar to raise/1
1 parent eab6f41 commit b6e7fa2

File tree

2 files changed

+3
-22
lines changed

2 files changed

+3
-22
lines changed

lib/elixir/lib/kernel.ex

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1743,26 +1743,7 @@ defmodule Kernel do
17431743

17441744
message ->
17451745
quote do
1746-
stacktrace = unquote(stacktrace)
1747-
1748-
case unquote(message) do
1749-
message when is_binary(message) ->
1750-
:erlang.raise(:error, RuntimeError.exception(message), stacktrace)
1751-
1752-
atom when is_atom(atom) ->
1753-
:erlang.raise(:error, atom.exception([]), stacktrace)
1754-
1755-
%_{__exception__: true} = other ->
1756-
:erlang.raise(:error, other, stacktrace)
1757-
1758-
other ->
1759-
message = <<
1760-
"reraise/2 expects a module name, string or exception",
1761-
"as the first argument, got: #{inspect(other)}"
1762-
>>
1763-
1764-
:erlang.error(ArgumentError.exception(message))
1765-
end
1746+
:erlang.raise(:error, Kernel.Utils.raise(unquote(message)), unquote(stacktrace))
17661747
end
17671748
end
17681749
end

lib/elixir/lib/kernel/utils.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ defmodule Kernel.Utils do
135135

136136
def raise(other) do
137137
ArgumentError.exception(
138-
"raise/1 expects a module name, string or exception as " <>
139-
"the first argument, got: #{inspect(other)}"
138+
"raise/1 and reraise/2 expect a module name, string or exception " <>
139+
"as the first argument, got: #{inspect(other)}"
140140
)
141141
end
142142

0 commit comments

Comments
 (0)