Improve errors on reconnecting Mix runtime (#837)

This commit is contained in:
Jonatan Kłosko 2021-12-29 14:04:51 +01:00 committed by GitHub
parent 54ceaac551
commit d5d4e739d1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 5 deletions

View file

@ -83,9 +83,23 @@ defmodule Livebook.Runtime.MixStandalone do
init_async(project_path, emitter)
await_init(ref, [])
end
defp await_init(ref, outputs) do
receive do
{:emitter, ^ref, {:ok, runtime}} -> {:ok, runtime}
{:emitter, ^ref, {:error, error}} -> {:error, error}
{:emitter, ^ref, message} -> message
end
|> case do
{:ok, runtime} ->
{:ok, runtime}
{:error, error} ->
message = IO.iodata_to_binary([error, ". Output:\n\n", Enum.reverse(outputs)])
{:error, message}
{:output, output} ->
await_init(ref, [output | outputs])
end
end
@ -98,7 +112,7 @@ defmodule Livebook.Runtime.MixStandalone do
into: output_emitter
) do
{_callback, 0} -> :ok
{_callback, _status} -> {:error, "running mix #{task} failed, see output for more details"}
{_callback, _status} -> {:error, "running mix #{task} failed"}
end
end

View file

@ -741,7 +741,7 @@ defmodule LivebookWeb.SessionLive do
case Runtime.duplicate(runtime) do
{:ok, new_runtime} ->
Session.connect_runtime(socket.assigns.session.pid, new_runtime)
socket
clear_flash(socket, :error)
{:error, message} ->
put_flash(socket, :error, "Failed to setup runtime - #{message}")

View file

@ -1,5 +1,5 @@
<main role="main" class="flex-grow flex flex-col h-screen">
<div class="fixed right-8 bottom-5 z-50 flex flex-col space-y-3">
<div class="fixed right-8 bottom-5 z-50 flex flex-col space-y-3 max-h-[80%] overflow-y-auto tiny-scrollbar">
<%= if live_flash(@flash, :info) do %>
<div class="shadow-custom-1 max-w-2xl flex items-center space-x-3 rounded-lg px-4 py-2 border-l-4 rounded-l-none border-blue-500 bg-white text-gray-600 hover:bg-gray-50 hover:text-gray-500 cursor-pointer" role="alert"
phx-click="lv:clear-flash"