Skip to content

Commit 288bc2d

Browse files
committed
Move function to schema
1 parent 04faf06 commit 288bc2d

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

lib/error_tracker/schemas/error.ex

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,14 @@ defmodule ErrorTracker.Error do
5555
|> Ecto.Changeset.put_change(:last_occurrence_at, DateTime.utc_now())
5656
|> Ecto.Changeset.apply_action(:new)
5757
end
58+
59+
@doc """
60+
Returns if the Error has information of the source or not.
61+
62+
Errors usually have information about in which line and function occurred, but
63+
in some cases (like an Oban job ending with `{:error, any()}`) we cannot get
64+
that information and no source is stored.
65+
"""
66+
defp has_source_info?(%Error{source_function: "-", source_line: "-"}), do: false
67+
defp has_source_info?(%Error{}), do: true
5868
end

lib/error_tracker/web/live/dashboard.html.heex

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,9 @@
6969
<p class="whitespace-nowrap text-ellipsis w-full overflow-hidden">
7070
(<%= sanitize_module(error.kind) %>) <%= error.reason %>
7171
</p>
72-
<p :if={error.source_function != "-"} class="font-normal text-gray-400">
72+
<p :if={ErrorTracker.Error.has_source_info?(error)} class="font-normal text-gray-400">
7373
<%= sanitize_module(error.source_function) %>
74-
</p>
75-
<p :if={error.source_function != "-"} class="font-normal text-gray-400">
74+
<br />
7675
<%= error.source_line %>
7776
</p>
7877
</td>

lib/error_tracker/web/live/show.ex

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,4 @@ defmodule ErrorTracker.Web.Live.Show do
121121
|> limit(^num_results)
122122
|> Repo.all()
123123
end
124-
125-
defp error_has_source_info?(%Error{source_function: "-", source_line: "-"}), do: false
126-
defp error_has_source_info?(%Error{}), do: true
127124
end

lib/error_tracker/web/live/show.html.heex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<pre class="overflow-auto p-4 rounded-lg bg-gray-300/10 border border-gray-900"><%= @occurrence.reason %></pre>
2020
</.section>
2121

22-
<.section :if={error_has_source_info?(@error)} title="Source">
22+
<.section :if={ErrorTracker.Error.has_source_info?(@error)} title="Source">
2323
<pre class="overflow-auto text-sm p-4 rounded-lg bg-gray-300/10 border border-gray-900">
2424
<%= sanitize_module(@error.source_function) %>
2525
<%= @error.source_line %></pre>

0 commit comments

Comments
 (0)