Skip to content

Commit

Permalink
fix crash in build when printing invalid diagnostics from external co…
Browse files Browse the repository at this point in the history
…mpilers

we can't assume that diagnostic details is a correct error tuple
  • Loading branch information
lukaszsamson committed Jan 11, 2024
1 parent ebb0511 commit 6c84c34
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions apps/language_server/lib/language_server/diagnostics.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,17 @@ defmodule ElixirLS.LanguageServer.Diagnostics do
# don't include stacktrace in exceptions with position
message =
if diagnostic.file not in [nil, "nofile"] and diagnostic.position != 0 and
is_tuple(diagnostic.details) and tuple_size(diagnostic.details) == 2 do
is_tuple(diagnostic.details) and tuple_size(diagnostic.details) == 2 and
elem(diagnostic.details, 0) in [:error, :throw, :exit] do
{kind, reason} = diagnostic.details
Exception.format_banner(kind, reason)

try do
Exception.format_banner(kind, reason)
rescue
_ ->
# we can't trust that details from external compilers will behave
diagnostic.message
end
else
diagnostic.message
end
Expand Down

0 comments on commit 6c84c34

Please sign in to comment.