Skip to content

Commit 547e1c7

Browse files
committed
Capture errors with Plug.Debugger
1 parent 15c7e58 commit 547e1c7

File tree

3 files changed

+43
-5
lines changed

3 files changed

+43
-5
lines changed

lib/mix/tasks/tableau.build.ex

+16-5
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,17 @@ defmodule Mix.Tasks.Tableau.Build do
4444
pages =
4545
pages
4646
|> Task.async_stream(fn {mod, page} ->
47-
content = Tableau.Document.render(graph, mod, token, page)
48-
permalink = Nodable.permalink(mod)
49-
50-
Map.merge(page, %{body: content, permalink: permalink})
47+
try do
48+
content = Tableau.Document.render(graph, mod, token, page)
49+
permalink = Nodable.permalink(mod)
50+
51+
Map.merge(page, %{body: content, permalink: permalink})
52+
rescue
53+
exception ->
54+
reraise Tableau.BuildException, [page: page, exception: exception], __STACKTRACE__
55+
end
5156
end)
52-
|> Stream.map(fn {:ok, result} -> result end)
57+
|> Stream.map(&map_pages/1)
5358
|> Enum.to_list()
5459

5560
token = put_in(token.site[:pages], pages)
@@ -74,6 +79,12 @@ defmodule Mix.Tasks.Tableau.Build do
7479
token
7580
end
7681

82+
defp map_pages({:ok, result}), do: result
83+
84+
defp map_pages({:exit, {exception, stacktrace}}) do
85+
reraise exception, stacktrace
86+
end
87+
7788
@file_extensions [".html"]
7889
defp build_file_path(out, permalink) do
7990
if Path.extname(permalink) in @file_extensions do

lib/tableau.ex

+26
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,29 @@ defmodule Tableau do
5151
MDEx.to_html!(content, Keyword.merge(config.markdown[:mdex], overrides))
5252
end
5353
end
54+
55+
defmodule Tableau.BuildException do
56+
@moduledoc false
57+
@type t :: %__MODULE__{
58+
page: map(),
59+
exception: any()
60+
}
61+
62+
defexception [:page, :exception]
63+
64+
@impl true
65+
def exception(page: page, exception: exception) do
66+
%__MODULE__{page: page, exception: exception}
67+
end
68+
69+
@impl true
70+
def message(%__MODULE__{page: page, exception: exception}) do
71+
"""
72+
An exception was raised:
73+
#{Exception.format_banner(:error, exception)}
74+
75+
occurred during the build process on the page:
76+
#{inspect(page, pretty: true)}
77+
"""
78+
end
79+
end

lib/tableau_dev_server/router.ex

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
defmodule TableauDevServer.Router do
22
@moduledoc false
33
use Plug.Router, init_mode: :runtime
4+
use Plug.Debugger
45

56
require Logger
67

0 commit comments

Comments
 (0)