Skip to content

Commit ee56234

Browse files
author
José Valim
committed
Ensure halt on system cmd collectable
1 parent fca45d8 commit ee56234

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

lib/elixir/lib/system.ex

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,15 +452,24 @@ defmodule System do
452452

453453
{into, opts} = cmd_opts(opts, [:use_stdio, :exit_status, :binary, :hide, args: args], "")
454454
{initial, fun} = Collectable.into(into)
455-
do_cmd Port.open({:spawn_executable, cmd}, opts), initial, fun
455+
try do
456+
do_cmd Port.open({:spawn_executable, cmd}, opts), initial, fun
457+
catch
458+
kind, reason ->
459+
stacktrace = System.stacktrace
460+
fun.(initial, :halt)
461+
:erlang.raise(kind, reason, stacktrace)
462+
else
463+
{acc, status} -> {fun.(acc, :done), status}
464+
end
456465
end
457466

458467
defp do_cmd(port, acc, fun) do
459468
receive do
460469
{^port, {:data, data}} ->
461470
do_cmd(port, fun.(acc, {:cont, data}), fun)
462471
{^port, {:exit_status, status}} ->
463-
{fun.(acc, :done), status}
472+
{acc, status}
464473
end
465474
end
466475

0 commit comments

Comments
 (0)