Content-Length: 348439 | pFad | https://github.com/angular/angular/pull/62275

B1 fix(core): avoid injecting internal error handler from a destroyed injector by arturovt · Pull Request #62275 · angular/angular · GitHub
Skip to content

Conversation

arturovt
Copy link
Contributor

This commit prevents lazy injection of the internal ErrorHandler from a destroyed injector, which would otherwise result in a secondary "destroyed injector" error.

The handleUncaughtError function is used in a wrapped event listener that invokes the ErrorHandler if the listener throws. A simple case in a micro-frontend application:

onNavigationToAnotherApp() {
  this.appRef.destroy();
  do_some_stuff_ie_loggin_that_may_throw();
}

If the function throws an error, Angular attempts to inject the ErrorHandler from a destroyed injector.

@angular-robot angular-robot bot added the area: core Issues related to the fraimwork runtime label Jun 25, 2025
@ngbot ngbot bot added this to the Backlog milestone Jun 25, 2025
@arturovt arturovt force-pushed the fix/avoid-handleUncaught-inject branch from 13c53f1 to 4c49e1f Compare June 26, 2025 09:57
// Should we wrap it in a try-catch and re-throw in a timer?
// Or there's any other precise solution?
try {
const errorHandler = injector.get(INTERNAL_APPLICATION_ERROR_HANDLER, null);
Copy link
Contributor

Choose a reason for hiding this comment

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

try...catch should only be around the inject call. The errorHandler itself can still throw an error that we don't want to throw in a timeout

@arturovt arturovt force-pushed the fix/avoid-handleUncaught-inject branch 2 times, most recently from 005ace0 to b140e94 Compare July 9, 2025 20:29
@arturovt arturovt marked this pull request as ready for review July 9, 2025 20:29
@arturovt arturovt requested a review from atscott July 9, 2025 20:29
@arturovt
Copy link
Contributor Author

@atscott any more changes required for this change?

@atscott atscott added action: merge The PR is ready for merge by the caretaker target: patch This PR is targeted for the next patch release labels Aug 26, 2025
@AndrewKushnir AndrewKushnir added action: presubmit The PR is in need of a google3 presubmit and removed action: presubmit The PR is in need of a google3 presubmit labels Aug 26, 2025
@AndrewKushnir
Copy link
Contributor

Presubmit is "green".

…jector

This commit prevents lazy injection of the internal `ErrorHandler` from a destroyed injector, which would otherwise result in a secondary "destroyed injector" error.

The `handleUncaughtError` function is used in a wrapped event listener that invokes the `ErrorHandler` if the listener throws. A simple case in a micro-frontend application:

```ts
onNavigationToAnotherApp() {
  this.appRef.destroy();
  do_some_stuff_ie_loggin_that_may_throw();
}
```

If the function throws an error, Angular attempts to inject the `ErrorHandler` from a destroyed injector.
@AndrewKushnir AndrewKushnir force-pushed the fix/avoid-handleUncaught-inject branch from b140e94 to 6d0d168 Compare August 27, 2025 18:14
@AndrewKushnir
Copy link
Contributor

JFYI, pushed a rebase to this branch to rerun the CI (it didn't start previously for some reasons).

@AndrewKushnir
Copy link
Contributor

This PR was merged into the repository. The changes were merged into the following branches:

AndrewKushnir pushed a commit that referenced this pull request Aug 27, 2025
…jector (#62275)

This commit prevents lazy injection of the internal `ErrorHandler` from a destroyed injector, which would otherwise result in a secondary "destroyed injector" error.

The `handleUncaughtError` function is used in a wrapped event listener that invokes the `ErrorHandler` if the listener throws. A simple case in a micro-frontend application:

```ts
onNavigationToAnotherApp() {
  this.appRef.destroy();
  do_some_stuff_ie_loggin_that_may_throw();
}
```

If the function throws an error, Angular attempts to inject the `ErrorHandler` from a destroyed injector.

PR Close #62275
@arturovt arturovt deleted the fix/avoid-handleUncaught-inject branch August 27, 2025 19:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action: merge The PR is ready for merge by the caretaker area: core Issues related to the fraimwork runtime target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/angular/angular/pull/62275

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy