Skip to content

Commit 5398f3a

Browse files
author
Andrew Hall
authored
Fix RemoteInvocationException reporting (#9596)
The initial IFaultExceptionHandler MEF construction was no longer working due to refactoring. This changes it to no longer use MEF and just report directly. Also update the ExceptionStrategy to ISerializable, since that will set the InnerException property if the other end of the connection is the same. This will make error reporting for us contain remote stacks instead of our own. If that's not the case, we still report as much as we can. Anyone looking for more information on jsonrpc errors can look at microsoft/vs-streamjsonrpc@main/doc/exceptions.md
1 parent 82dae72 commit 5398f3a

File tree

4 files changed

+21
-51
lines changed

4 files changed

+21
-51
lines changed

src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/JsonRPCFaultExceptionHandler.cs

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorLanguageServer.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,6 @@ protected override ILspServices ConstructLspServices()
164164
services.AddSingleton<WorkspaceDirectoryPathResolver, DefaultWorkspaceDirectoryPathResolver>();
165165
services.AddSingleton<RazorComponentSearchEngine, DefaultRazorComponentSearchEngine>();
166166

167-
services.AddSingleton<IFaultExceptionHandler, JsonRPCFaultExceptionHandler>();
168-
169167
// Get the DefaultSession for telemetry. This is set by VS with
170168
// TelemetryService.SetDefaultSession and provides the correct
171169
// appinsights keys etc

src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Telemetry/IFaultExceptionHandler.cs

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/Razor/src/Microsoft.VisualStudio.Editor.Razor/Telemetry/VSTelemetryReporter.cs

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,55 @@
22
// Licensed under the MIT license. See License.txt in the project root for license information.
33

44
using System;
5-
using System.Collections.Generic;
65
using System.Collections.Immutable;
76
using System.Composition;
87
using Microsoft.Extensions.Logging;
98
using Microsoft.VisualStudio.Telemetry;
9+
using StreamJsonRpc;
1010

1111
namespace Microsoft.AspNetCore.Razor.Telemetry;
1212

1313
[Shared]
1414
[Export(typeof(ITelemetryReporter))]
1515
internal class VSTelemetryReporter : TelemetryReporter
1616
{
17-
private readonly IEnumerable<IFaultExceptionHandler> _faultExceptionHandlers;
1817
private readonly ILogger? _logger;
1918

2019
[ImportingConstructor]
2120
public VSTelemetryReporter(
22-
[Import(AllowDefault = true)] ILoggerFactory? loggerFactory = null,
23-
[ImportMany] IEnumerable<IFaultExceptionHandler>? faultExceptionHandlers = null)
21+
[Import(AllowDefault = true)] ILoggerFactory? loggerFactory = null)
2422
// Get the DefaultSession for telemetry. This is set by VS with
2523
// TelemetryService.SetDefaultSession and provides the correct
2624
// appinsights keys etc
2725
: base(ImmutableArray.Create(TelemetryService.DefaultSession))
2826
{
29-
_faultExceptionHandlers = faultExceptionHandlers ?? Array.Empty<IFaultExceptionHandler>();
3027
_logger = loggerFactory?.CreateLogger<VSTelemetryReporter>();
3128
}
3229

3330
protected override bool HandleException(Exception exception, string? message, params object?[] @params)
3431
{
35-
var handled = false;
36-
foreach (var handler in _faultExceptionHandlers)
32+
if (exception is RemoteInvocationException remoteInvocationException)
3733
{
38-
if (handler.HandleException(this, exception, message, @params))
39-
{
40-
// This behavior means that each handler still gets a chance
41-
// to respond to the exception. There's no real reason for this other
42-
// than best guess. When it was added, there was only one handler but
43-
// it was intended to be easy to add more.
44-
handled = true;
45-
}
34+
ReportRemoteInvocationException(remoteInvocationException);
35+
return true;
4636
}
4737

48-
return handled;
38+
return false;
39+
}
40+
41+
private void ReportRemoteInvocationException(RemoteInvocationException remoteInvocationException)
42+
{
43+
if (remoteInvocationException.InnerException is Exception innerException)
44+
{
45+
ReportFault(innerException, "RIE: " + remoteInvocationException.Message);
46+
return;
47+
}
48+
49+
ReportFault(
50+
remoteInvocationException,
51+
remoteInvocationException.Message,
52+
remoteInvocationException.ErrorCode,
53+
remoteInvocationException.DeserializedErrorData);
4954
}
5055

5156
protected override void LogTrace(string? message, params object?[] args)

0 commit comments

Comments
 (0)