Skip to content

Commit 946feba

Browse files
authored
Fix Phoenix.LiveView.Debug.live_components not returning :error (#3861)
* Add test for live_components returning :error * Fix catching :exit in live_components
1 parent e2f9c02 commit 946feba

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

lib/phoenix_live_view/debug.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ defmodule Phoenix.LiveView.Debug do
133133
"""
134134
def live_components(liveview_pid) do
135135
GenServer.call(liveview_pid, {:phoenix, :debug_live_components})
136-
rescue
137-
_ -> {:error, :not_alive_or_not_a_liveview}
136+
catch
137+
:exit, _ -> {:error, :not_alive_or_not_a_liveview}
138138
end
139139
end

test/phoenix_live_view/debug_test.exs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,18 @@ defmodule Phoenix.LiveView.DebugTest do
3333
end
3434
end
3535

36+
defmodule NotALiveView do
37+
use GenServer
38+
39+
def start_link(opts) do
40+
GenServer.start_link(__MODULE__, opts)
41+
end
42+
43+
def init(opts) do
44+
{:ok, opts}
45+
end
46+
end
47+
3648
describe "list_liveviews/0" do
3749
test "returns a list of all currently connected LiveView processes" do
3850
conn = Plug.Test.conn(:get, "/")
@@ -64,18 +76,6 @@ defmodule Phoenix.LiveView.DebugTest do
6476
end
6577

6678
test "returns an error if the given pid is not a LiveView process" do
67-
defmodule NotALiveView do
68-
use GenServer
69-
70-
def start_link(opts) do
71-
GenServer.start_link(__MODULE__, opts)
72-
end
73-
74-
def init(opts) do
75-
{:ok, opts}
76-
end
77-
end
78-
7979
pid = start_supervised!(NotALiveView)
8080
assert {:error, :not_alive_or_not_a_liveview} = Debug.socket(pid)
8181
end
@@ -89,5 +89,10 @@ defmodule Phoenix.LiveView.DebugTest do
8989
assert {:ok, [%{id: "component-1", module: TestLV.Component}]} =
9090
Debug.live_components(view.pid)
9191
end
92+
93+
test "returns an error if the given pid is not a LiveView process" do
94+
pid = start_supervised!(NotALiveView)
95+
assert {:error, :not_alive_or_not_a_liveview} = Debug.live_components(pid)
96+
end
9297
end
9398
end

0 commit comments

Comments
 (0)