Fix error recovery when serializing unknown structs in JS view payload

This commit is contained in:
Jonatan Kłosko 2022-08-04 00:28:32 +02:00
parent 732db0ed45
commit 6853bbd9a1

View file

@ -105,14 +105,17 @@ defmodule LivebookWeb.JSViewChannel do
defp run_safely(fun) do defp run_safely(fun) do
try do try do
{:ok, fun.()} {:ok, fun.()}
catch rescue
:error, %Protocol.UndefinedError{protocol: Jason.Encoder, value: value} -> error ->
case error do
%Protocol.UndefinedError{protocol: Jason.Encoder, value: value} ->
{:error, "value #{inspect(value)} is not JSON-serializable, use another data type"} {:error, "value #{inspect(value)} is not JSON-serializable, use another data type"}
:error, error -> error ->
{:error, Exception.message(error)} {:error, Exception.message(error)}
end end
end end
end
defp fastlane_encoder({:event, event, payload, %{ref: ref}}) do defp fastlane_encoder({:event, event, payload, %{ref: ref}}) do
run_safely(fn -> run_safely(fn ->