Skip to content

Commit d6bcad7

Browse files
committed
Show error if dev supervisor fails to start
1 parent 5874abc commit d6bcad7

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

lib/surface/catalogue/server.ex

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,27 @@ defmodule Surface.Catalogue.Server do
8989
Application.put_env(:surface_catalogue, __MODULE__.Endpoint, merge_opts(default_opts, opts))
9090
Application.put_env(:phoenix, :serve_endpoints, true)
9191

92-
Task.start(fn ->
92+
Task.start_link(fn ->
93+
require Logger
94+
Process.flag(:trap_exit, true)
95+
9396
children = [
9497
{Phoenix.PubSub, [name: __MODULE__.PubSub, adapter: Phoenix.PubSub.PG2]},
9598
{__MODULE__.Endpoint, [log_access_url: false]}
9699
]
97100

98-
{:ok, _} = Supervisor.start_link(children, strategy: :one_for_one)
99-
require Logger
100-
Logger.info("Access Surface Catalogue at #{__MODULE__.Endpoint.url()}/catalogue")
101-
Process.sleep(:infinity)
101+
case Supervisor.start_link(children, strategy: :one_for_one) do
102+
{:ok, _} ->
103+
Logger.info("Access Surface Catalogue at #{__MODULE__.Endpoint.url()}/catalogue")
104+
Process.sleep(:infinity)
105+
106+
{:error, payload} ->
107+
payload
108+
|> Exception.format_exit()
109+
|> Logger.error()
110+
111+
System.stop(1)
112+
end
102113
end)
103114
end
104115

test/catalogue_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ defmodule Surface.Catalogue.CatalogueTest do
77
live_view: [signing_salt: "hMegieSe"]
88
)
99

10-
start_supervised(Surface.Catalogue.Server.Endpoint)
10+
start_supervised!(Surface.Catalogue.Server.Endpoint)
1111

1212
:ok
1313
end

0 commit comments

Comments
 (0)