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

Skip to content

Commit 538de86

Browse files
arturovtAndrewKushnir
authored andcommitted
fix(core): avoid injecting internal error handler from a destroyed injector (#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
1 parent 3a3bd36 commit 538de86

File tree

1 file changed

+6
-1
lines changed
  • packages/core/src/render3/instructions

1 file changed

+6
-1
lines changed

‎packages/core/src/render3/instructions/shared.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,12 @@ export function handleUncaughtError(lView: LView, error: any): void {
705705
if (!injector) {
706706
return;
707707
}
708-
const errorHandler = injector.get(INTERNAL_APPLICATION_ERROR_HANDLER, null);
708+
let errorHandler: ((e: any) => void) | null;
709+
try {
710+
errorHandler = injector.get(INTERNAL_APPLICATION_ERROR_HANDLER, null);
711+
} catch {
712+
errorHandler = null;
713+
}
709714
errorHandler?.(error);
710715
}
711716

0 commit comments

Comments
 (0)