Skip to content

Commit 6c84c34

Browse files
committed
fix crash in build when printing invalid diagnostics from external compilers
we can't assume that diagnostic details is a correct error tuple
1 parent ebb0511 commit 6c84c34

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

apps/language_server/lib/language_server/diagnostics.ex

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,17 @@ defmodule ElixirLS.LanguageServer.Diagnostics do
3030
# don't include stacktrace in exceptions with position
3131
message =
3232
if diagnostic.file not in [nil, "nofile"] and diagnostic.position != 0 and
33-
is_tuple(diagnostic.details) and tuple_size(diagnostic.details) == 2 do
33+
is_tuple(diagnostic.details) and tuple_size(diagnostic.details) == 2 and
34+
elem(diagnostic.details, 0) in [:error, :throw, :exit] do
3435
{kind, reason} = diagnostic.details
35-
Exception.format_banner(kind, reason)
36+
37+
try do
38+
Exception.format_banner(kind, reason)
39+
rescue
40+
_ ->
41+
# we can't trust that details from external compilers will behave
42+
diagnostic.message
43+
end
3644
else
3745
diagnostic.message
3846
end

0 commit comments

Comments
 (0)