Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(core): Ensure errors in listeners report to the application error… #60251

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

Closed
wants to merge 1 commit into from

Conversation

atscott
Copy link
Contributor

@atscott atscott commented Mar 6, 2025

… handler

Practically speaking, this change ensures that Angular is able to make decisions about what to do when an uncaught error happens.

For tests, this will mean that, by default, the error either causes the fixture.whenStable promise to reject if there is one or rethrow the error. This ensures tests do not accidentally ignore errors. Opting out of this can be done with the rethrowApplicationErrors: false option in TestBed.

For SSR, there may be additional behaviors in the future that we want to add, such as redirecting to an error page or responding with a 500 status code.

BREAKING CHANGE: Uncaught errors in listeners which were previously only reported to ErrorHandler are now also reported to Angular's internal error handling machinery. For tests, this means that the error will be rethrown by default rather than only logging the error. Developers should fix these errors, catch them in the test if the test is intentionally covering an error case, or use rethrowApplicationErrors: false in configureTestingModule as a last resort.

@atscott atscott added area: testing Issues related to Angular testing features, such as TestBed area: core Issues related to the framework runtime target: major This PR is targeted for the next major release labels Mar 6, 2025
@ngbot ngbot bot modified the milestone: Backlog Mar 6, 2025
@angular-robot angular-robot bot added the detected: breaking change PR contains a commit with a breaking change label Mar 6, 2025
@atscott atscott added breaking changes and removed detected: breaking change PR contains a commit with a breaking change labels Mar 6, 2025
@atscott atscott force-pushed the listenerReportToAppHandler branch from d0b2667 to 547682c Compare March 31, 2025 17:41
@angular-robot angular-robot bot added the detected: breaking change PR contains a commit with a breaking change label Mar 31, 2025
@atscott atscott force-pushed the listenerReportToAppHandler branch from 547682c to 9c4f90f Compare March 31, 2025 18:02
… handler

Practically speaking, this change ensures that Angular is able to make
decisions about what to do when an uncaught error happens.

For tests, this will mean that, by default, the error either causes the
`fixture.whenStable` promise to reject if there is one or rethrow the
error. This ensures tests do not accidentally ignore errors. Opting out
of this can be done with the `rethrowApplicationErrors: false` option in
`TestBed`.

For SSR, there may be additional behaviors in the future that we want to
add, such as redirecting to an error page or responding with a 500
status code.

BREAKING CHANGE: Uncaught errors in listeners which were previously only reported to
`ErrorHandler` are now also reported to Angular's internal error
handling machinery. For tests, this means that the error will be
rethrown by default rather than only logging the error. Developers
should fix these errors, catch them in the test if the test is
intentionally covering an error case, or use `rethrowApplicationErrors:
false` in `configureTestingModule` as a last resort.
@atscott atscott force-pushed the listenerReportToAppHandler branch from 9c4f90f to 9c63777 Compare March 31, 2025 18:28
@atscott
Copy link
Contributor Author

atscott commented Mar 31, 2025

Green TGP. TGP CL contains 2 local changes that have been sent to reviewers. We can also get global approver during sync if needed (LSC already approved)

@atscott atscott added the action: merge The PR is ready for merge by the caretaker label Apr 1, 2025
@ngbot
Copy link

ngbot bot commented Apr 1, 2025

I see that you just added the action: merge label, but the following checks are still failing:
    failure status "google-internal-tests" is failing

If you want your PR to be merged, it has to pass all the CI checks.

If you can't get the PR to a green state due to flakes or broken main, please try rebasing to main and/or restarting the CI job. If that fails and you believe that the issue is not due to your change, please contact the caretaker and ask for help.

@thePunderWoman
Copy link
Contributor

This PR was merged into the repository by commit 7b819be.

The changes were merged into the following branches: main

@Platonn
Copy link
Contributor

Platonn commented Apr 14, 2025

I'm really happy Angular may plan to propagate errors to SSR, so it returns e.g. 500 error page.

As a contribution, let me share this thought:
If possible, it would be nice if the solution doesn't break the previous behavior, which allowed developers to show 500 error page - i.e. which allowed developers to capture the errors themselves in their custom ErrorHandler and propagate to SSR (via their custom SSR wrapper). At least, IMHO this custom solution should not be forbidden, until an official Angular's solution for showing 500 page is released.

For example, in our Angular ecommerce meta-framework Spartacus, we've already implemented such a mechanism - we capture errors in our custom global ErrorHandler and propagate it via a custom injectable callback PROPAGATE_ERROR_TO_SERER up to the SSR layer. This injectable was provided on the platform-injector-level by the customized CommonEngine.render method - which rejects a SSR rendering promise in case when the error was propagated.

For other feedbacks from our team on the error handling in SSR, feel free to see the historical discussions in those Angular issues/PRs:

Again, many thanks for your long-term willingness to improve error handling in SSR 🙌

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators May 18, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker area: core Issues related to the framework runtime area: testing Issues related to Angular testing features, such as TestBed breaking changes detected: breaking change PR contains a commit with a breaking change target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants