From 8d537afd35a09df638f79f57dc12f0209316ad0d Mon Sep 17 00:00:00 2001 From: Cristine Guadelupe Date: Mon, 4 Sep 2023 20:03:35 +0700 Subject: [PATCH] Applying suggestions --- lib/kino/remote_cell.ex | 27 +++++++++++---------------- test/kino/remote_cell.exs | 1 + 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/lib/kino/remote_cell.ex b/lib/kino/remote_cell.ex index d8257c06..3c19120d 100644 --- a/lib/kino/remote_cell.ex +++ b/lib/kino/remote_cell.ex @@ -40,15 +40,11 @@ defmodule Kino.RemoteCell do end @impl true - def to_source(attrs) do - attrs |> to_quoted() |> Kino.SmartCell.quoted_to_string() - end - - defp to_quoted(%{"node" => ""}), do: build_empty() - defp to_quoted(%{"cookie" => ""}), do: build_empty() - defp to_quoted(%{"code" => ""}), do: build_empty() + def to_source(%{"node" => ""}), do: "" + def to_source(%{"cookie" => ""}), do: "" + def to_source(%{"code" => ""}), do: "" - defp to_quoted(%{"code" => code} = attrs) do + def to_source(%{"code" => code} = attrs) do code = Code.string_to_quoted(code) to_quoted(attrs, code) end @@ -64,12 +60,16 @@ defmodule Kino.RemoteCell do Node.connect(node) unquote(call) end + |> Kino.SmartCell.quoted_to_string() end defp to_quoted(%{"code" => code}, {:error, _reason}) do - quote do - Code.string_to_quoted!(unquote(code)) - end + "# Invalid code for RPC, reproducing the error below\n" <> + Kino.SmartCell.quoted_to_string( + quote do + Code.string_to_quoted!(unquote(code)) + end + ) end defp build_call(code) do @@ -85,9 +85,4 @@ defmodule Kino.RemoteCell do unquote({String.to_atom(var), [], nil}) = unquote(call) end end - - defp build_empty() do - quote do - end - end end diff --git a/test/kino/remote_cell.exs b/test/kino/remote_cell.exs index 5ec0c75e..24b48c70 100644 --- a/test/kino/remote_cell.exs +++ b/test/kino/remote_cell.exs @@ -65,6 +65,7 @@ defmodule Kino.RemoteCellTest do attrs = %{@fields | "code" => "1 + "} assert RemoteCell.to_source(attrs) == """ + # Invalid code for RPC, reproducing the error below Code.string_to_quoted!("1 + ")\ """ end