Skip to content

Commit 7cf4369

Browse files
michalmuskalaJosé Valim
authored andcommitted
Issue warning instead of error for unhandled messages
While the change to start logging unhandled messages from handle_info/2 is a good one, the choice to issue "error" level events was a poor one. Code that worked perfectly fine on previous versions suddenly started issuing errors, which is unexpected. A "warn" level log seems to be a better choice, at least initially. The log level can be revisited in the future. Signed-off-by: José Valim <jose.valim@plataformatec.com.br>
1 parent 4135ab1 commit 7cf4369

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

lib/elixir/lib/gen_server.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,8 +568,8 @@ defmodule GenServer do
568568
{_, []} -> self()
569569
{_, name} -> name
570570
end
571-
:error_logger.error_msg('~p ~p received unexpected message in handle_info/2: ~p~n',
572-
[__MODULE__, proc, msg])
571+
:error_logger.warning_msg('~p ~p received unexpected message in handle_info/2: ~p~n',
572+
[__MODULE__, proc, msg])
573573
{:noreply, state}
574574
end
575575

lib/elixir/test/elixir/gen_server_test.exs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ Code.require_file "test_helper.exs", __DIR__
33
defmodule GenServerTest do
44
use ExUnit.Case, async: true
55

6+
import ExUnit.CaptureLog
7+
68
defmodule Stack do
79
use GenServer
810

@@ -161,4 +163,13 @@ defmodule GenServerTest do
161163
{:ok, _} = GenServer.start(Stack, [], name: :stack_for_stop)
162164
assert GenServer.stop(:stack_for_stop, :normal) == :ok
163165
end
166+
167+
test "handle_info/2 warning" do
168+
{:ok, pid} = GenServer.start(Stack, [])
169+
log = capture_log(fn ->
170+
send(pid, :foo)
171+
GenServer.stop(pid)
172+
end)
173+
assert log =~ "[warn] GenServerTest.Stack #{inspect pid} received unexpected message in handle_info/2: :foo"
174+
end
164175
end

0 commit comments

Comments
 (0)