mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-12-16 21:28:03 +08:00
Ignore code server error logs when checking for modules (#1971)
This commit is contained in:
parent
57bd761b74
commit
c383c7aaff
3 changed files with 34 additions and 1 deletions
|
|
@ -15,4 +15,18 @@ defmodule Livebook.Runtime.ErlDist.LoggerGLHandler do
|
||||||
def async_io(device, output) when is_pid(device) do
|
def async_io(device, output) when is_pid(device) do
|
||||||
send(device, {:io_request, self(), make_ref(), {:put_chars, :unicode, output}})
|
send(device, {:io_request, self(), make_ref(), {:put_chars, :unicode, output}})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@doc false
|
||||||
|
def filter_code_server_logs(%{meta: meta} = event, _) do
|
||||||
|
# When checking if a miscapitalized module, such as Io, is loaded,
|
||||||
|
# :code_server logs an error message on a case insensitive file
|
||||||
|
# system "Error loading module 'Elixir.Io'". We want to ignore
|
||||||
|
# such logs
|
||||||
|
|
||||||
|
if Process.whereis(:code_server) == meta.pid do
|
||||||
|
:stop
|
||||||
|
else
|
||||||
|
event
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -99,7 +99,11 @@ defmodule Livebook.Runtime.ErlDist.NodeManager do
|
||||||
# TODO: remove logger backend once we require Elixir v1.15
|
# TODO: remove logger backend once we require Elixir v1.15
|
||||||
if Code.ensure_loaded?(Logger) and function_exported?(Logger, :add_handlers, 1) do
|
if Code.ensure_loaded?(Logger) and function_exported?(Logger, :add_handlers, 1) do
|
||||||
:logger.add_handler(:livebook_gl_handler, Livebook.Runtime.ErlDist.LoggerGLHandler, %{
|
:logger.add_handler(:livebook_gl_handler, Livebook.Runtime.ErlDist.LoggerGLHandler, %{
|
||||||
formatter: Logger.Formatter.new()
|
formatter: Logger.Formatter.new(),
|
||||||
|
filters: [
|
||||||
|
code_server_logs:
|
||||||
|
{&Livebook.Runtime.ErlDist.LoggerGLHandler.filter_code_server_logs/2, nil}
|
||||||
|
]
|
||||||
})
|
})
|
||||||
else
|
else
|
||||||
Logger.add_backend(Livebook.Runtime.ErlDist.LoggerGLBackend)
|
Logger.add_backend(Livebook.Runtime.ErlDist.LoggerGLBackend)
|
||||||
|
|
|
||||||
|
|
@ -166,6 +166,21 @@ defmodule Livebook.Runtime.ErlDist.RuntimeServerTest do
|
||||||
assert_receive {:runtime_intellisense_response, ^ref, ^request,
|
assert_receive {:runtime_intellisense_response, ^ref, ^request,
|
||||||
%{items: [%{label: "bright/0"}]}}
|
%{items: [%{label: "bright/0"}]}}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@tag capture_log: true
|
||||||
|
test "ignores code server error logs when loading mistyped module", %{pid: pid} do
|
||||||
|
RuntimeServer.evaluate_code(pid, :elixir, "", {:c1, :e1}, [])
|
||||||
|
assert_receive {:runtime_evaluation_response, :e1, _, %{evaluation_time_ms: _time_ms}}
|
||||||
|
|
||||||
|
request = {:completion, "Io."}
|
||||||
|
ref = RuntimeServer.handle_intellisense(pid, self(), request, [])
|
||||||
|
|
||||||
|
assert_receive {:runtime_intellisense_response, ^ref, ^request, %{items: []}}
|
||||||
|
|
||||||
|
# Checking if the module is loaded results in "Error loading module 'Elixir.Io'"
|
||||||
|
# error log, which should be ignored
|
||||||
|
refute_receive {:runtime_evaluation_output, :e1, {:stdout, _log_message}}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "handle_intellisense/5 given details request" do
|
describe "handle_intellisense/5 given details request" do
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue