Skip to content

Commit

Permalink
Draft - Include more information on AlreadySentError errors
Browse files Browse the repository at this point in the history
We have an app that is getting a lot of AlreadySentErrors. Likely
somewhere we have missed an `halt()`, but tracking that down is tricky.
I wonder if we could supply some more information in the various places
the error gets raised to help someone debug the issue?

Exact wording and contents can be discussed.
  • Loading branch information
Adzz committed Dec 5, 2024
1 parent 5e62a39 commit ad5174a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/phoenix/controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,9 @@ defmodule Phoenix.Controller do
if state in @unsent do
put_private_layout(conn, :phoenix_layout, :replace, layout)
else
raise AlreadySentError
raise AlreadySentError, """
The response was already sent. Request was to `#{conn.request_path}` using #{inspect(layout)}\
"""
end
end

Expand Down
4 changes: 3 additions & 1 deletion test/phoenix/controller/controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ defmodule Phoenix.Controller.ControllerTest do
conn = put_format(conn, "print")
assert layout(conn) == {AppView, :print}

assert_raise Plug.Conn.AlreadySentError, fn ->
message = "The response was already sent. Request was to `/` using {AppView, :print}"

assert_raise Plug.Conn.AlreadySentError, message, fn ->
put_layout(sent_conn(), {AppView, :print})
end
end
Expand Down

0 comments on commit ad5174a

Please sign in to comment.