Conversation
solnic
added this pull request to stack #1225
September 22, 2026 07:48
solnic
marked this pull request as ready for review
September 22, 2026 09:11
solnic
force-pushed
the
fix/wrap-plug-and-phoenix-callbacks
branch
from
September 22, 2026 10:06
32d5a7d to
80ace99
Compare
|
|
||
| @moduledoc since: "10.5.0" | ||
|
|
||
| import Phoenix.LiveView, only: [attach_hook: 4, get_connect_info: 2] |
There was a problem hiding this comment.
Bug: An invalid :remote_address_reader option for Sentry.PlugContext causes an uncaught ArgumentError, crashing the request despite documentation promising that callback failures are handled.
Severity: MEDIUM
Suggested Fix
Ensure that exceptions raised during callback preparation are also caught. This could be achieved by moving the Sentry.Callback.to_fun/3 call inside the Sentry.Callback.run/2 function or by wrapping the call in plug_context.ex with a try/rescue block to handle potential ArgumentError exceptions gracefully, thus upholding the documented guarantee.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: lib/sentry/live_view_hook.ex#L89
Potential issue: If an invalid value is provided for the `:remote_address_reader` option
in `Sentry.PlugContext` (e.g., a string or atom instead of a function or tuple), the
call to `Sentry.Callback.to_fun/3` will raise an `ArgumentError`. This exception is not
caught because it occurs before `Sentry.Callback.run/2` is invoked, which is intended to
handle callback failures. This behavior contradicts the documentation's promise that
callback failures will not affect the request, leading to an uncaught exception that
crashes the request process upon misconfiguration.
Also affects:
lib/sentry/live_view_hook.ex:150~150
Did we get this right? 👍 / 👎 to inform future reviews.
solnic
force-pushed
the
fix/wrap-plug-and-phoenix-callbacks
branch
from
September 23, 2026 14:43
80ace99 to
8e0f744
Compare
sl0thentr0py
approved these changes
Sep 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Now the callbacks reachable from a web request -
remote_address_reader, thePlugContextscrubbers (body_scrubber,header_scrubber,cookie_scrubber,url_scrubber) and thePlugCapture/LiveViewHookscrubber- run throughSentry.Callback. A crash is logged as anerrorwith:sentrylog domain and the SDK falls back to its own default scrubbing, so the request is served as if nothing happened.Two specific fixes on top of the wrapping: while capturing, a failure inside Sentry never replaces the application's own exception — the original one keeps propagating unchanged, and the LiveView hook scrubber falls back to empty data instead of raising, since raising in a hook takes down the LiveView process.
A scrubber that returns the wrong type now falls back to the default scrubber and is logged as a
warning. PreviouslyPlugCaptureandLiveViewHookraised on a bad return value, so it was reported as a crash with a stacktrace, while the equivalentPlugContextcase was a warning — they all report it the same way now.