Skip to content

Commit

Permalink
Merge pull request #19209 from unoplatform/dev/dr/hrUpdates
Browse files Browse the repository at this point in the history
fix(devSrv): Do not fail connection if a client processor fails
  • Loading branch information
dr1rrb authored Jan 14, 2025
2 parents b5f75b2 + 9eb8d0e commit 11272fa
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 13 deletions.
19 changes: 14 additions & 5 deletions src/Uno.UI.RemoteControl/HotReload/ClientHotReloadProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public async Task ProcessFrame(Messages.Frame frame)
private async Task ConfigureServer()
{
var assembly = _rcClient.AppType.Assembly;
if (assembly.GetCustomAttributes(typeof(ProjectConfigurationAttribute), false) is ProjectConfigurationAttribute[] configs)
if (assembly.GetCustomAttributes(typeof(ProjectConfigurationAttribute), false) is ProjectConfigurationAttribute[] { Length: > 0 } configs)
{
_status.ReportServerState(HotReloadState.Initializing);

Expand All @@ -85,14 +85,23 @@ private async Task ConfigureServer()
_status.ReportInvalidRuntime();
}

ConfigureServer message = new(_projectPath, GetMetadataUpdateCapabilities(), _serverMetadataUpdatesEnabled, config.MSBuildProperties);
var message = new ConfigureServer(_projectPath, GetMetadataUpdateCapabilities(), _serverMetadataUpdatesEnabled, config.MSBuildProperties);

await _rcClient.SendMessage(message);

if (this.Log().IsEnabled(LogLevel.Trace))
{
this.Log().Trace($"Successfully sent request to configure HR server for project '{_projectPath}'.");
}
}
catch
catch (Exception error)
{
_status.ReportServerState(HotReloadState.Disabled);
throw;

if (this.Log().IsEnabled(LogLevel.Error))
{
this.Log().LogError("Unable to configure HR server", error);
}
}
}
else
Expand All @@ -101,7 +110,7 @@ private async Task ConfigureServer()

if (this.Log().IsEnabled(LogLevel.Error))
{
this.Log().LogError("Unable to find ProjectConfigurationAttribute");
this.Log().LogError("Unable to configure HR server as ProjectConfigurationAttribute is missing.");
}
}
}
Expand Down
35 changes: 27 additions & 8 deletions src/Uno.UI.RemoteControl/RemoteControlClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,17 @@ private async Task ProcessMessages(WebSocket socket, CancellationToken ct)

foreach (var processor in _processors)
{
await processor.Value.Initialize();
try
{
await processor.Value.Initialize();
}
catch (Exception error)
{
if (this.Log().IsEnabled(LogLevel.Error))
{
this.Log().LogError($"Failed to initialize processor '{processor}'.", error);
}
}
}

StartKeepAliveTimer();
Expand All @@ -526,14 +536,23 @@ private async Task ProcessMessages(WebSocket socket, CancellationToken ct)
this.Log().Trace($"Received frame [{frame.Scope}/{frame.Name}]");
}

bool skipProcessing = false;

var skipProcessing = false;
foreach (var preProcessor in _preprocessors)
{
if (await preProcessor.SkipProcessingFrame(frame))
try
{
if (await preProcessor.SkipProcessingFrame(frame))
{
skipProcessing = true;
break;
}
}
catch (Exception error)
{
skipProcessing = true;
break;
if (this.Log().IsEnabled(LogLevel.Error))
{
this.Log().LogError($"Error while **PRE**processing frame [{frame.Scope}/{frame.Name}]", error);
}
}
}

Expand All @@ -554,9 +573,9 @@ private async Task ProcessMessages(WebSocket socket, CancellationToken ct)
}
else
{
if (this.Log().IsEnabled(LogLevel.Error))
if (this.Log().IsEnabled(LogLevel.Trace))
{
this.Log().LogError($"Unknown Frame scope {frame.Scope}");
this.Log().Trace($"Unknown Frame scope {frame.Scope}");
}
}
}
Expand Down

0 comments on commit 11272fa

Please sign in to comment.