From 913e8d6312cea37e83fac10f8c04ef4b0a6b8504 Mon Sep 17 00:00:00 2001 From: Mitchell Hanberg Date: Wed, 4 Oct 2023 23:55:55 -0400 Subject: [PATCH] fix: add defensive logging in runtime (#276) --- lib/next_ls/runtime.ex | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/next_ls/runtime.ex b/lib/next_ls/runtime.ex index 957d9fa9..e7ec445e 100644 --- a/lib/next_ls/runtime.ex +++ b/lib/next_ls/runtime.ex @@ -70,12 +70,15 @@ defmodule NextLS.Runtime do path = System.get_env("PATH") new_path = String.replace(path, bindir <> ":", "") - with dir when is_list(dir) <- :code.priv_dir(:next_ls) do + with dir when is_list(dir) <- :code.priv_dir(:next_ls), + elixir_exe when is_binary(elixir_exe) <- System.find_executable("elixir") do exe = dir |> Path.join("cmd") |> Path.absname() + NextLS.Logger.log(logger, "Using `elixir` found at: #{elixir_exe}") + port = Port.open( {:spawn_executable, exe}, @@ -98,7 +101,7 @@ defmodule NextLS.Runtime do {~c"PATH", String.to_charlist(new_path)} ], args: - [System.find_executable("elixir")] ++ + [elixir_exe] ++ if @env == :test do ["--erl", "-kernel prevent_overlapping_partitions false"] else @@ -178,6 +181,11 @@ defmodule NextLS.Runtime do }} else _ -> + NextLS.Logger.error( + logger, + "Either failed to find the private cmd wrapper script or an `elixir`exe on your PATH" + ) + {:stop, :failed_to_boot} end end