From d2aa3d27ff55c934c56b905fb6d97e505a947c5c Mon Sep 17 00:00:00 2001 From: Lukasz Samson Date: Sun, 19 May 2024 17:20:53 +0200 Subject: [PATCH] validate dialyzer options invalid options lead unhandled to crashes --- .../lib/language_server/dialyzer/analyzer.ex | 2 ++ .../lib/language_server/server.ex | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/apps/language_server/lib/language_server/dialyzer/analyzer.ex b/apps/language_server/lib/language_server/dialyzer/analyzer.ex index 9c911d744..1d1a1b3c1 100644 --- a/apps/language_server/lib/language_server/dialyzer/analyzer.ex +++ b/apps/language_server/lib/language_server/dialyzer/analyzer.ex @@ -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 diff --git a/apps/language_server/lib/language_server/server.ex b/apps/language_server/lib/language_server/server.ex index a3ef09fd7..d10be5327 100644 --- a/apps/language_server/lib/language_server/server.ex +++ b/apps/language_server/lib/language_server/server.ex @@ -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 = [