Skip to content

Commit d3c3793

Browse files
committed
do not crash if unable to translate contract
1 parent 4d0c09f commit d3c3793

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

apps/language_server/lib/language_server/providers/code_lens/type_spec/contract_translator.ex

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ defmodule ElixirLS.LanguageServer.Providers.CodeLens.TypeSpec.ContractTranslator
33
alias Erl2exVendored.Convert.{Context, ErlForms}
44
alias Erl2exVendored.Pipeline.{Parse, ModuleData, ExSpec}
55

6+
require Logger
7+
68
def translate_contract(fun, contract, is_macro, mod) do
79
# FIXME: Private module
810
{[%ExSpec{specs: [spec]} | _], _} =
@@ -26,6 +28,11 @@ defmodule ElixirLS.LanguageServer.Providers.CodeLens.TypeSpec.ContractTranslator
2628
|> Code.format_string!(line_length: :infinity)
2729
|> IO.iodata_to_binary()
2830
|> String.replace_prefix("foo", to_string(fun))
31+
rescue
32+
CompileError ->
33+
# Parse.string can raise CompileError if the spec is invalid
34+
Logger.warning("Failed to translate contract for #{mod}.#{fun}/#{length(contract)}")
35+
nil
2936
end
3037

3138
defp tweak_specs({:list, _meta, args}) do

0 commit comments

Comments
 (0)