From 9e38c7a32199d869aa34519649108e16236b65de Mon Sep 17 00:00:00 2001 From: David Date: Fri, 8 Nov 2024 16:24:57 -0500 Subject: [PATCH] chore: Avoid duplicated logs and prevent error bubbling --- src/Uno.UI.RemoteControl.VS/EntryPoint.cs | 55 ++++++++--------------- 1 file changed, 19 insertions(+), 36 deletions(-) diff --git a/src/Uno.UI.RemoteControl.VS/EntryPoint.cs b/src/Uno.UI.RemoteControl.VS/EntryPoint.cs index 8a9b81a8df58..4fab39943dd9 100644 --- a/src/Uno.UI.RemoteControl.VS/EntryPoint.cs +++ b/src/Uno.UI.RemoteControl.VS/EntryPoint.cs @@ -442,71 +442,54 @@ private async Task OnMessageReceivedAsync(object? sender, IdeMessage devServerMe switch (devServerMessage) { case AddMenuItemRequestIdeMessage amir: - await OnAddMenuItemRequestIdeMessageAsync(sender, amir); + await OnAddMenuItemRequestedAsync(sender, amir); break; case ForceHotReloadIdeMessage fhr: await OnForceHotReloadRequestedAsync(sender, fhr); break; case NotificationRequestIdeMessage nr: - await NotificationRequestIdeMessageAsync(sender, nr); + await OnNotificationRequestedAsync(sender, nr); break; default: _debugAction?.Invoke($"Unknown message type {devServerMessage?.GetType()} from DevServer"); break; } } - catch (Exception e) when (_ideChannelClient is not null) + catch (Exception e) { _debugAction?.Invoke($"Failed to handle IdeMessage with message {e.Message}"); - throw; } } - private async Task NotificationRequestIdeMessageAsync(object? sender, NotificationRequestIdeMessage message) + private async Task OnNotificationRequestedAsync(object? sender, NotificationRequestIdeMessage message) { - try - { - await _asyncPackage.JoinableTaskFactory.SwitchToMainThreadAsync(); + await _asyncPackage.JoinableTaskFactory.SwitchToMainThreadAsync(); - if (await _asyncPackage.GetServiceAsync(typeof(SVsShell)) is IVsShell shell && - await _asyncPackage.GetServiceAsync(typeof(SVsInfoBarUIFactory)) is IVsInfoBarUIFactory infoBarFactory) - { - await CreateInfoBarAsync(message, shell, infoBarFactory); - } - } - catch (Exception e) when (_ideChannelClient is not null) + if (await _asyncPackage.GetServiceAsync(typeof(SVsShell)) is IVsShell shell && + await _asyncPackage.GetServiceAsync(typeof(SVsInfoBarUIFactory)) is IVsInfoBarUIFactory infoBarFactory) { - _debugAction?.Invoke($"Failed to handle InfoBar Notification Requested with message {e.Message}"); - throw; + await CreateInfoBarAsync(message, shell, infoBarFactory); } } - private async Task OnAddMenuItemRequestIdeMessageAsync(object? sender, AddMenuItemRequestIdeMessage cr) + private async Task OnAddMenuItemRequestedAsync(object? sender, AddMenuItemRequestIdeMessage cr) { - try + if (_ideChannelClient == null) { - if (_ideChannelClient == null) - { - return; - } + return; + } - if (_unoMenuCommand is not null) - { - //ignore when duplicated - if (!_unoMenuCommand.CommandList.Contains(cr)) - { - _unoMenuCommand.CommandList.Add(cr); - } - } - else + if (_unoMenuCommand is not null) + { + //ignore when duplicated + if (!_unoMenuCommand.CommandList.Contains(cr)) { - _unoMenuCommand = await UnoMenuCommand.InitializeAsync(_asyncPackage, _ideChannelClient, cr); + _unoMenuCommand.CommandList.Add(cr); } } - catch (Exception e) + else { - _debugAction?.Invoke($"Using AddMenuItem Ide Message Requested fail {e.Message}"); - throw; + _unoMenuCommand = await UnoMenuCommand.InitializeAsync(_asyncPackage, _ideChannelClient, cr); } }