Skip to content
This repository was archived by the owner on Oct 8, 2025. It is now read-only.

Commit a972a4f

Browse files
committed
fix: improve error handling for compiler diagnostics
1 parent 2b83c33 commit a972a4f

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

lib/next_ls/extensions/elixir_extension.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ defmodule NextLS.ElixirExtension do
2424
end
2525

2626
@impl GenServer
27-
def handle_info({:compiler, diagnostics}, state) do
27+
def handle_info({:compiler, diagnostics}, state) when is_list(diagnostics) do
2828
DiagnosticCache.clear(state.cache, :elixir)
2929

3030
for d <- diagnostics do

lib/next_ls/runtime.ex

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ defmodule NextLS.Runtime do
120120
NextLS.Logger.log(logger, "The runtime for #{name} has successfully shutdown.")
121121

122122
reason ->
123-
NextLS.Logger.error(logger, "The runtime for #{name} has crashed with reason: #{reason}.")
123+
NextLS.Logger.error(logger, "The runtime for #{name} has crashed with reason: #{inspect(reason)}.")
124124
end
125125
end
126126
end)
@@ -136,8 +136,8 @@ defmodule NextLS.Runtime do
136136
|> Path.join("monkey/_next_ls_private_compiler.ex")
137137
|> then(&:rpc.call(node, Code, :compile_file, [&1]))
138138
|> tap(fn
139-
{:badrpc, :EXIT, {error, _}} ->
140-
NextLS.Logger.error(logger, error)
139+
{:badrpc, error} ->
140+
NextLS.Logger.error(logger, {:badrpc, error})
141141

142142
_ ->
143143
:ok
@@ -192,15 +192,22 @@ defmodule NextLS.Runtime do
192192
def handle_call(:compile, from, %{node: node} = state) do
193193
task =
194194
Task.Supervisor.async_nolink(state.task_supervisor, fn ->
195-
{_, errors} = :rpc.call(node, :_next_ls_private_compiler, :compile, [])
195+
case :rpc.call(node, :_next_ls_private_compiler, :compile, []) do
196+
{:badrpc, error} ->
197+
NextLS.Logger.error(state.logger, {:badrpc, error})
198+
[]
196199

197-
Registry.dispatch(state.registry, :extensions, fn entries ->
198-
for {pid, _} <- entries do
199-
send(pid, {:compiler, errors})
200-
end
201-
end)
200+
{_, diagnostics} when is_list(diagnostics) ->
201+
Registry.dispatch(state.registry, :extensions, fn entries ->
202+
for {pid, _} <- entries, do: send(pid, {:compiler, diagnostics})
203+
end)
202204

203-
errors
205+
diagnostics
206+
207+
unknown ->
208+
NextLS.Logger.warning(state.logger, "Unexpected compiler response: #{inspect(unknown)}")
209+
[]
210+
end
204211
end)
205212

206213
{:noreply, %{state | compiler_ref: %{task.ref => from}}}

0 commit comments

Comments
 (0)