Skip to content

Commit 1a2f3ff

Browse files
committed
fix crash when process is no longer paused when handling async variables request
1 parent e19dfe9 commit 1a2f3ff

File tree

1 file changed

+27
-16
lines changed
  • apps/elixir_ls_debugger/lib/debugger

1 file changed

+27
-16
lines changed

apps/elixir_ls_debugger/lib/debugger/server.ex

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -384,9 +384,12 @@ defmodule ElixirLS.Debugger.Server do
384384
_from,
385385
state = %__MODULE__{}
386386
) do
387-
{state, var_id} = get_variable_reference(child_type, state, pid, value)
388-
389-
{:reply, var_id, state}
387+
if Map.has_key?(state.paused_processes, pid) do
388+
{state, var_id} = get_variable_reference(child_type, state, pid, value)
389+
{:reply, {:ok, var_id}, state}
390+
else
391+
{:reply, {:error, :not_paused}, state}
392+
end
390393
end
391394

392395
@impl GenServer
@@ -1179,7 +1182,7 @@ defmodule ElixirLS.Debugger.Server do
11791182

11801183
child_type = Variables.child_type(value)
11811184
# we need to call here as get_variable_reference modifies the state
1182-
var_id =
1185+
{:ok, var_id} =
11831186
GenServer.call(__MODULE__, {:get_variable_reference, child_type, :evaluator, value})
11841187

11851188
%{
@@ -1398,19 +1401,27 @@ defmodule ElixirLS.Debugger.Server do
13981401
|> Enum.reduce([], fn {name, value}, acc ->
13991402
child_type = Variables.child_type(value)
14001403

1401-
var_id =
1402-
GenServer.call(__MODULE__, {:get_variable_reference, child_type, pid, value})
1404+
case GenServer.call(__MODULE__, {:get_variable_reference, child_type, pid, value}) do
1405+
{:ok, var_id} ->
1406+
json =
1407+
%{
1408+
"name" => to_string(name),
1409+
"value" => inspect(value),
1410+
"variablesReference" => var_id
1411+
}
1412+
|> maybe_append_children_number(state.client_info, child_type, value)
1413+
|> maybe_append_variable_type(state.client_info, value)
14031414

1404-
json =
1405-
%{
1406-
"name" => to_string(name),
1407-
"value" => inspect(value),
1408-
"variablesReference" => var_id
1409-
}
1410-
|> maybe_append_children_number(state.client_info, child_type, value)
1411-
|> maybe_append_variable_type(state.client_info, value)
1412-
1413-
[json | acc]
1415+
[json | acc]
1416+
1417+
{:error, :not_paused} ->
1418+
raise ServerError,
1419+
message: "runtimeError",
1420+
format: "pid no longer paused: {pid}",
1421+
variables: %{
1422+
"pid" => inspect(pid)
1423+
}
1424+
end
14141425
end)
14151426
|> Enum.reverse()
14161427
end

0 commit comments

Comments
 (0)