Skip to content

Commit

Permalink
Add report for "normal" exits in IEx (#13753)
Browse files Browse the repository at this point in the history
  • Loading branch information
tywhisky authored Aug 1, 2024
1 parent 4629fb6 commit f6d8eb4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
23 changes: 8 additions & 15 deletions lib/iex/lib/iex/server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -266,16 +266,14 @@ defmodule IEx.Server do
input,
_callback
) do
if abnormal_reason?(reason) do
try do
io_error(
"** (EXIT from #{inspect(evaluator)}) shell process exited with reason: " <>
Exception.format_exit(reason)
)
catch
type, detail ->
io_error("** (IEx.Error) #{type} when printing EXIT message: #{inspect(detail)}")
end
try do
io_error(
"** (EXIT from #{inspect(evaluator)}) shell process exited with reason: " <>
Exception.format_exit(reason)
)
catch
type, detail ->
io_error("** (IEx.Error) #{type} when printing EXIT message: #{inspect(detail)}")
end

rerun(state, [], evaluator, evaluator_ref, input)
Expand All @@ -285,11 +283,6 @@ defmodule IEx.Server do
callback.(state)
end

defp abnormal_reason?(:normal), do: false
defp abnormal_reason?(:shutdown), do: false
defp abnormal_reason?({:shutdown, _}), do: false
defp abnormal_reason?(_), do: true

defp take_over?(take_pid, take_ref, take_location, take_whereami, take_opts, counter) do
evaluator = take_opts[:evaluator] || self()
message = "Request to pry #{inspect(evaluator)} at #{take_location}#{take_whereami}"
Expand Down
10 changes: 10 additions & 0 deletions lib/iex/test/iex/interaction_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,16 @@ defmodule IEx.InteractionTest do
~r"\*\* \(EXIT from #PID<\d+\.\d+\.\d+>\) shell process exited with reason: {:bye, \[:world\]}"
end

test "receive normal exits" do
assert capture_iex("spawn_link(fn -> exit(:normal) end); Process.sleep(1000)") =~ ":ok"

assert capture_iex("spawn_link(fn -> exit(:shutdown) end); Process.sleep(1000)") =~
~r"\*\* \(EXIT from #PID<\d+\.\d+\.\d+>\) shell process exited with reason: shutdown"

assert capture_iex("spawn_link(fn -> exit({:shutdown, :bye}) end); Process.sleep(1000)") =~
~r"\*\* \(EXIT from #PID<\d+\.\d+\.\d+>\) shell process exited with reason: shutdown: :bye"
end

test "receive exit from exception" do
# use exit/1 to fake an error so that an error message
# is not sent to the error logger.
Expand Down

0 comments on commit f6d8eb4

Please sign in to comment.