Skip to content

Commit c66e452

Browse files
authored
Add LiveView event to context only during exceptions (#78)
As @odarriba and @numso discussed on #74 the current approach of adding LiveView event information to the process context may result in misleading information for certain errors. > For example, if the following happened: > > 1. mount the liveview > 2. handle_event("something", params, socket) in the liveview > 3. handle_info("something_else", socket) causing a re-render > 4. render -> exception occurs > > I think live_view.event and live_view.event_params would still be in the error context when the exception was reported. They would have been assigned to context in step 2. But by step 4, that data could be irrelevant. Am I understanding that right? This pull request adds the LiveView event information to the context only during exceptions and avoids the situations mentioned above. The LiveView name, URL and URL params are still part of the process context as that information is helpful to understand what was going on before the error happened. This is consistent with the LiveComponent error handled implemented in #74
1 parent 317432f commit c66e452

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

lib/error_tracker/integrations/phoenix.ex

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ defmodule ErrorTracker.Integrations.Phoenix do
5858
[:phoenix, :live_view, :mount, :exception],
5959
[:phoenix, :live_view, :handle_params, :start],
6060
[:phoenix, :live_view, :handle_params, :exception],
61-
[:phoenix, :live_view, :handle_event, :start],
6261
[:phoenix, :live_view, :handle_event, :exception],
6362
[:phoenix, :live_view, :render, :exception],
6463
[:phoenix, :live_component, :update, :exception],
@@ -103,8 +102,8 @@ defmodule ErrorTracker.Integrations.Phoenix do
103102
})
104103
end
105104

106-
def handle_event([:phoenix, :live_view, :handle_event, :start], _, metadata, :no_config) do
107-
ErrorTracker.set_context(%{
105+
def handle_event([:phoenix, :live_view, :handle_event, :exception], _, metadata, :no_config) do
106+
ErrorTracker.report({metadata.kind, metadata.reason}, metadata.stacktrace, %{
108107
"live_view.event" => metadata.event,
109108
"live_view.event_params" => metadata.params
110109
})

0 commit comments

Comments
 (0)