-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Wrap OnNavigateTo callback with GetErrorHandledTask for proper exception logging #62414
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
base: main
Are you sure you want to change the base?
Conversation
Greetings human! You've submitted a PR that modifies code that is shared with https://github.com/dotnet/runtime . Please make sure you synchronize this code with the changes in that repo! |
…ion logging Co-authored-by: ilonatommy <[email protected]>
OnNavigateTo
are logged
Make a test in src/Components/Components/test/NavigationManagerTest.cs for the case when |
@@ -83,7 +83,11 @@ internal async Task InitializeStandardComponentServicesAsync( | |||
IFormCollection? form = null) | |||
{ | |||
var navigationManager = httpContext.RequestServices.GetRequiredService<NavigationManager>(); | |||
((IHostEnvironmentNavigationManager)navigationManager)?.Initialize(GetContextBaseUri(httpContext.Request), GetFullUri(httpContext.Request), OnNavigateTo); | |||
((IHostEnvironmentNavigationManager)navigationManager)?.Initialize(GetContextBaseUri(httpContext.Request), GetFullUri(httpContext.Request), uri => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check out
aspnetcore/src/Components/Components/src/Routing/IHostEnvironmentNavigationManager.cs
Line 25 in ee050bd
void Initialize(string baseUri, string uri, Func<string, Task> onNavigateTo) => |
Initialize(string baseUri, string uri, Func<string, Task> onNavigateTo)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to use the correct Initialize(string baseUri, string uri, Func<string, Task> onNavigateTo)
method signature. The lambda now directly returns the Task
from GetErrorHandledTask(OnNavigateTo(uri))
instead of wrapping it and returning Task.CompletedTask
. Fixed in commit 80512e6.
…nagerTest.cs Co-authored-by: ilonatommy <[email protected]>
I've added the requested test in NavigationManagerTest.cs. The test Fixed in commit 949150a. |
Co-authored-by: ilonatommy <[email protected]>
Exceptions thrown in the
OnNavigateTo
callback were not being logged because the callback was passed directly toNavigationManager.Initialize()
without error handling. WhenRemoteNavigationManager
invokes this callback using the fire-and-forget pattern (_ = _onNavigateTo(absoluteUriString)
), any exceptions are silently discarded.This change wraps the
OnNavigateTo
callback withGetErrorHandledTask
, following the same pattern already established for theOnNotFound
handler in the same method.Before:
After:
The
GetErrorHandledTask
method catches exceptions and logs them appropriately, ensuring that navigation errors are visible for debugging rather than being silently ignored.Fixes #62413.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.