From 066172149ed5b8e853277764f494e6519402df7c Mon Sep 17 00:00:00 2001 From: Jens Fischer Date: Tue, 20 Feb 2018 20:09:05 +0100 Subject: [PATCH] Fix DynamicSupervisor error report when restarting child --- lib/elixir/lib/dynamic_supervisor.ex | 8 ++++---- lib/logger/test/logger/translator_test.exs | 24 ++++++++++++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/lib/elixir/lib/dynamic_supervisor.ex b/lib/elixir/lib/dynamic_supervisor.ex index 3fdfc378197..85ec16f646f 100644 --- a/lib/elixir/lib/dynamic_supervisor.ex +++ b/lib/elixir/lib/dynamic_supervisor.ex @@ -963,21 +963,21 @@ defmodule DynamicSupervisor do end end - defp report_error(error, reason, pid, child, %{name: name}) do + defp report_error(error, reason, pid, child, %{name: name, extra_arguments: extra}) do :error_logger.error_report( :supervisor_report, supervisor: name, errorContext: error, reason: reason, - offender: extract_child(pid, child) + offender: extract_child(pid, child, extra) ) end - defp extract_child(pid, {mfa, restart, shutdown, type, _modules}) do + defp extract_child(pid, {{m, f, args}, restart, shutdown, type, _modules}, extra) do [ pid: pid, id: :undefined, - mfargs: mfa, + mfargs: {m, f, extra ++ args}, restart_type: restart, shutdown: shutdown, child_type: type diff --git a/lib/logger/test/logger/translator_test.exs b/lib/logger/test/logger/translator_test.exs index da6e15e9b2d..45bcff54fc9 100644 --- a/lib/logger/test/logger/translator_test.exs +++ b/lib/logger/test/logger/translator_test.exs @@ -711,6 +711,26 @@ defmodule Logger.TranslatorTest do """ end + test "translates DynamicSupervisor reports extra_arguments in in abnormal shutdown" do + assert capture_log(:info, fn -> + trap = Process.flag(:trap_exit, true) + + {:ok, pid} = + DynamicSupervisor.start_link(strategy: :one_for_one, extra_arguments: [:extra]) + + child = %{id: __MODULE__, start: {__MODULE__, :abnormal2, [:args]}} + {:ok, _pid2} = DynamicSupervisor.start_child(pid, child) + Process.exit(pid, :normal) + receive do: ({:EXIT, ^pid, _} -> :ok) + Process.flag(:trap_exit, trap) + end) =~ ~r""" + \[error\] Child :undefined of Supervisor #PID<\d+\.\d+\.\d+> \(Supervisor\.Default\) shutdown abnormally + \*\* \(exit\) :stop + Pid: #PID<\d+\.\d+\.\d+> + Start Call: Logger.TranslatorTest.abnormal2\(:extra, :args\) + """ + end + test "translates :supervisor_bridge progress" do assert capture_log(:info, fn -> trap = Process.flag(:trap_exit, true) @@ -804,6 +824,10 @@ defmodule Logger.TranslatorTest do :proc_lib.start_link(__MODULE__, :abnormal_init, []) end + def abnormal2(:extra, :args) do + :proc_lib.start_link(__MODULE__, :abnormal_init, []) + end + def abnormal_init() do Process.flag(:trap_exit, true) :proc_lib.init_ack({:ok, self()})