Skip to content

Commit d699da9

Browse files
committed
log error on invalid input in formatter.exs
1 parent 9ea1aec commit d699da9

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

apps/language_server/lib/language_server/providers/formatting.ex

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ defmodule ElixirLS.LanguageServer.Providers.Formatting do
33
alias ElixirLS.LanguageServer.Protocol.TextEdit
44
alias ElixirLS.LanguageServer.SourceFile
55
alias ElixirLS.LanguageServer.JsonRpc
6+
require Logger
67

78
def format(%SourceFile{} = source_file, uri = "file:" <> _, project_dir, mix_project?)
89
when is_binary(project_dir) do
@@ -77,8 +78,20 @@ defmodule ElixirLS.LanguageServer.Providers.Formatting do
7778
file_path = SourceFile.Path.absolute_from_uri(file_uri, project_dir)
7879

7980
Enum.any?(inputs, fn input_glob ->
80-
glob = Path.join(formatter_exs_dir, input_glob)
81-
PathGlobVendored.match?(file_path, glob, match_dot: true)
81+
try do
82+
glob = Path.join(formatter_exs_dir, input_glob)
83+
PathGlobVendored.match?(file_path, glob, match_dot: true)
84+
rescue
85+
error ->
86+
# Path.join crashes in case there is junk in input
87+
error_msg = Exception.format(:error, error, __STACKTRACE__)
88+
89+
Logger.error(
90+
"Unable to expand .formatter.exs input #{inspect(input_glob)}: #{error_msg}"
91+
)
92+
93+
false
94+
end
8295
end)
8396
end
8497

0 commit comments

Comments
 (0)