Skip to content

Commit

Permalink
validate dialyzer options
Browse files Browse the repository at this point in the history
invalid options lead unhandled to crashes
  • Loading branch information
lukaszsamson committed May 19, 2024
1 parent a9a038f commit d2aa3d2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions apps/language_server/lib/language_server/dialyzer/analyzer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ defmodule ElixirLS.LanguageServer.Dialyzer.Analyzer do
main_loop(state)
end

def all_warns, do: @default_warns ++ @non_default_warns

def matching_tags(warn_opts) do
default_warns =
unless :persistent_term.get(:language_server_test_mode, false) do
Expand Down
18 changes: 18 additions & 0 deletions apps/language_server/lib/language_server/server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1787,6 +1787,24 @@ defmodule ElixirLS.LanguageServer.Server do
else
IO.warn("Invalid `dialyzerWarnOpts` #{inspect(dialyzer_warn_opts)}")
end

all_warns = ElixirLS.LanguageServer.Dialyzer.Analyzer.all_warns() |> Enum.map(&to_string/1)

for opt <- dialyzer_warn_opts, opt not in all_warns do
Logger.error("Invalid `dialyzerWarnOpts`: unknown warning option `#{opt}`")

JsonRpc.show_message(
:error,
"Invalid `dialyzerWarnOpts` in configuration. Unknown warning option `#{opt}`."
)

unless :persistent_term.get(:language_server_test_mode, false) do
Process.sleep(2000)
System.halt(1)
else
IO.warn("Invalid `dialyzerWarnOpts`: unknown warning option `#{opt}`")
end
end
end

dialyzer_formats = [
Expand Down

0 comments on commit d2aa3d2

Please sign in to comment.