mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-09-08 22:14:58 +08:00
Rename error output :known_reason to :context
This commit is contained in:
parent
da9cc6643b
commit
b2ce588a1c
6 changed files with 23 additions and 17 deletions
|
@ -440,17 +440,17 @@ defprotocol Livebook.Runtime do
|
|||
@typedoc """
|
||||
Error content, usually representing evaluation failure.
|
||||
|
||||
The `:known_reason` field is used by Livebook to suggest a way to fix
|
||||
The `:context` field is used by Livebook to suggest a way to fix
|
||||
the error.
|
||||
"""
|
||||
@type error_output :: %{
|
||||
type: :error,
|
||||
message: String.t(),
|
||||
known_reason:
|
||||
context:
|
||||
{:missing_secret, name :: String.t()}
|
||||
| {:interrupt, variant :: :normal | :error, message :: String.t()}
|
||||
| {:file_entry_forbidden, name :: String.t()}
|
||||
| :other
|
||||
| nil
|
||||
}
|
||||
|
||||
@typedoc """
|
||||
|
|
|
@ -40,13 +40,13 @@ defmodule Livebook.Runtime.Evaluator.Formatter do
|
|||
|> error_color
|
||||
|> :erlang.list_to_binary()
|
||||
|
||||
%{type: :error, message: formatted, known_reason: error_known_reason(error)}
|
||||
%{type: :error, message: formatted, context: error_context(error)}
|
||||
end
|
||||
end
|
||||
|
||||
def format_result({:error, kind, error, stacktrace}, _language) do
|
||||
formatted = format_error(kind, error, stacktrace)
|
||||
%{type: :error, message: formatted, known_reason: error_known_reason(error)}
|
||||
%{type: :error, message: formatted, context: error_context(error)}
|
||||
end
|
||||
|
||||
def format_result({:ok, value}, :erlang) do
|
||||
|
@ -80,7 +80,7 @@ defmodule Livebook.Runtime.Evaluator.Formatter do
|
|||
catch
|
||||
kind, error ->
|
||||
formatted = format_error(kind, error, __STACKTRACE__)
|
||||
%{type: :error, message: formatted, known_reason: error_known_reason(error)}
|
||||
%{type: :error, message: formatted, context: error_context(error)}
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -159,16 +159,16 @@ defmodule Livebook.Runtime.Evaluator.Formatter do
|
|||
IO.ANSI.format([:red, string], true)
|
||||
end
|
||||
|
||||
defp error_known_reason(%System.EnvError{env: "LB_" <> secret_name}),
|
||||
defp error_context(%System.EnvError{env: "LB_" <> secret_name}),
|
||||
do: {:missing_secret, secret_name}
|
||||
|
||||
defp error_known_reason(error) when is_struct(error, Kino.InterruptError),
|
||||
defp error_context(error) when is_struct(error, Kino.InterruptError),
|
||||
do: {:interrupt, error.variant, error.message}
|
||||
|
||||
defp error_known_reason(error) when is_struct(error, Kino.FS.ForbiddenError),
|
||||
defp error_context(error) when is_struct(error, Kino.FS.ForbiddenError),
|
||||
do: {:file_entry_forbidden, error.name}
|
||||
|
||||
defp error_known_reason(_), do: :other
|
||||
defp error_context(_), do: nil
|
||||
|
||||
defp erlang_to_output(value) do
|
||||
text = :io_lib.format("~p", [value]) |> IO.iodata_to_binary()
|
||||
|
|
|
@ -2970,7 +2970,13 @@ defmodule Livebook.Session do
|
|||
end
|
||||
|
||||
defp normalize_runtime_output({:error, message, type}) do
|
||||
%{type: :error, message: message, known_reason: type}
|
||||
context =
|
||||
case type do
|
||||
:other -> nil
|
||||
type -> type
|
||||
end
|
||||
|
||||
%{type: :error, message: message, context: context}
|
||||
end
|
||||
|
||||
defp normalize_runtime_output(other) do
|
||||
|
|
|
@ -490,7 +490,7 @@ defmodule LivebookWeb.AppSessionLive do
|
|||
{idx, %{output | outputs: outputs}}
|
||||
end
|
||||
|
||||
defp filter_output({idx, %{type: :error, known_reason: {:interrupt, _, _}} = output}),
|
||||
defp filter_output({idx, %{type: :error, context: {:interrupt, _, _}} = output}),
|
||||
do: {idx, output}
|
||||
|
||||
defp filter_output(_output), do: nil
|
||||
|
|
|
@ -38,7 +38,7 @@ defmodule LivebookWeb.Output do
|
|||
end
|
||||
|
||||
defp border?(%{type: type}) when type in [:terminal_text, :plain_text], do: true
|
||||
defp border?(%{type: :error, known_reason: {:interrupt, _, _}}), do: false
|
||||
defp border?(%{type: :error, context: {:interrupt, _, _}}), do: false
|
||||
defp border?(%{type: :error}), do: true
|
||||
defp border?(%{type: :grid, boxed: boxed}), do: boxed
|
||||
defp border?(_output), do: false
|
||||
|
@ -253,7 +253,7 @@ defmodule LivebookWeb.Output do
|
|||
end
|
||||
|
||||
defp render_output(
|
||||
%{type: :error, known_reason: {:missing_secret, secret_name}} = output,
|
||||
%{type: :error, context: {:missing_secret, secret_name}} = output,
|
||||
%{session_id: session_id}
|
||||
) do
|
||||
assigns = %{message: output.message, secret_name: secret_name, session_id: session_id}
|
||||
|
@ -281,7 +281,7 @@ defmodule LivebookWeb.Output do
|
|||
end
|
||||
|
||||
defp render_output(
|
||||
%{type: :error, known_reason: {:file_entry_forbidden, file_entry_name}} = output,
|
||||
%{type: :error, context: {:file_entry_forbidden, file_entry_name}} = output,
|
||||
%{session_id: session_id}
|
||||
) do
|
||||
assigns = %{message: output.message, file_entry_name: file_entry_name, session_id: session_id}
|
||||
|
@ -309,7 +309,7 @@ defmodule LivebookWeb.Output do
|
|||
end
|
||||
|
||||
defp render_output(
|
||||
%{type: :error, known_reason: {:interrupt, variant, message}},
|
||||
%{type: :error, context: {:interrupt, variant, message}},
|
||||
%{cell_id: cell_id}
|
||||
) do
|
||||
assigns = %{variant: variant, message: message, cell_id: cell_id}
|
||||
|
|
|
@ -47,7 +47,7 @@ defmodule Livebook.Runtime.EvaluatorTest do
|
|||
|
||||
defmacrop error(message) do
|
||||
quote do
|
||||
%{type: :error, message: unquote(message), known_reason: :other}
|
||||
%{type: :error, message: unquote(message), context: nil}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue