Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include more information on AlreadySentError errors #6000

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Adzz
Copy link

@Adzz Adzz commented Dec 5, 2024

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? I have supplied a small example, but the exact wording and contents can be discussed.

I'm happy to roll this out to more places if we agree it's a good idea.

@Adzz Adzz force-pushed the give_more_info_for_not_sent_error branch 2 times, most recently from ad557ca to ad5174a Compare December 5, 2024 22:57
@@ -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)}\
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the request path should be in your logs/error handler anyway. Suggestion is to add information like the status code instead and response information.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ping :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah sorry, thanks for the reminder! I have pushed a thing see what you think :)

Adds more information to the AlreadySentError to help make debugging
them easier.
@Adzz Adzz force-pushed the give_more_info_for_not_sent_error branch from ad5174a to ad5136a Compare February 19, 2025 19:52
@Adzz Adzz marked this pull request as ready for review February 19, 2025 19:53
Copy link
Member

@josevalim josevalim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One comment and we should be good to go!

Comment on lines 592 to 597
The response was already sent.

Status code: `#{conn.status}`
Request path: `#{conn.request_path}`
Method: `#{conn.method}`
View module: `#{inspect(module)}`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error messages start in lowercase and I think the backticks would make things harder to read, so I suggest removing them:

Suggested change
The response was already sent.
Status code: `#{conn.status}`
Request path: `#{conn.request_path}`
Method: `#{conn.method}`
View module: `#{inspect(module)}`
the response was already sent.
Status code: #{conn.status}
Request path: #{conn.request_path}
Method: #{conn.method}
View module: #{inspect(module)}

@Adzz Adzz changed the title Draft - Include more information on AlreadySentError errors Include more information on AlreadySentError errors Feb 19, 2025
@Adzz Adzz force-pushed the give_more_info_for_not_sent_error branch from ad51317 to ad56eef Compare February 19, 2025 21:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants