diff --git a/src/EditorFeatures/TestUtilities/TestExtensionErrorHandler.cs b/src/EditorFeatures/TestUtilities/TestExtensionErrorHandler.cs index 1dca947569b3f03f74b7f12b0ba25a6f84f421b5..b0bbb5f0609bbf657f47742fa6f43a3efe077912 100644 --- a/src/EditorFeatures/TestUtilities/TestExtensionErrorHandler.cs +++ b/src/EditorFeatures/TestUtilities/TestExtensionErrorHandler.cs @@ -14,10 +14,13 @@ namespace Microsoft.CodeAnalysis.Editor.UnitTests { [Export(typeof(IExtensionErrorHandler))] + [Export(typeof(TestExtensionErrorHandler))] internal class TestExtensionErrorHandler : IExtensionErrorHandler { private ImmutableList _exceptions = ImmutableList.Empty; + public ImmutableList Exceptions => _exceptions; + [ImportingConstructor] [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] public TestExtensionErrorHandler() @@ -27,12 +30,24 @@ public TestExtensionErrorHandler() public void HandleError(object sender, Exception exception) { // Work around bug that is fixed in https://devdiv.visualstudio.com/DevDiv/_git/VS-Platform/pullrequest/209513 - if (exception is NullReferenceException && exception.StackTrace.Contains("SpanTrackingWpfToolTipPresenter")) + if (exception is NullReferenceException && + exception.StackTrace.Contains("SpanTrackingWpfToolTipPresenter")) + { + return; + } + + // Work around for https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1091056 + if (exception is InvalidOperationException && + exception.StackTrace.Contains("Microsoft.VisualStudio.Language.Intellisense.AsyncCompletion.Implementation.CompletionTelemetryHost")) { return; } - ExceptionUtilities.FailFast(exception); + // This exception is unexpected and as such we want the containing test case to + // fail. Unfortuntately throwing an exception here is not going to help because + // the editor is going to catch and swallow it. Store it here and wait for the + // containing workspace to notice it and throw. + _exceptions = _exceptions.Add(exception); } } } diff --git a/src/EditorFeatures/TestUtilities/Workspaces/TestWorkspace.cs b/src/EditorFeatures/TestUtilities/Workspaces/TestWorkspace.cs index b16bf3ab83e5fab7e901828f3145d23fda043e11..7bce916c59f9ddd5abd99e6eeae597bbdd27b7ff 100644 --- a/src/EditorFeatures/TestUtilities/Workspaces/TestWorkspace.cs +++ b/src/EditorFeatures/TestUtilities/Workspaces/TestWorkspace.cs @@ -48,6 +48,7 @@ public partial class TestWorkspace : Workspace private readonly BackgroundCompiler _backgroundCompiler; private readonly BackgroundParser _backgroundParser; private readonly IMetadataAsSourceFileService _metadataAsSourceFileService; + private readonly TestExtensionErrorHandler _testExtensionErrorHandler; private readonly Dictionary _createdTextBuffers = new Dictionary(); @@ -75,6 +76,7 @@ public TestWorkspace(ExportProvider exportProvider, string? workspaceKind = null _backgroundParser.Start(); _metadataAsSourceFileService = exportProvider.GetExportedValues().FirstOrDefault(); + _testExtensionErrorHandler = exportProvider.GetExportedValue(); RegisterDocumentOptionProviders(exportProvider.GetExports()); } @@ -142,6 +144,12 @@ protected override void Dispose(bool finalize) _backgroundParser.CancelAllParses(); } + var exceptions = _testExtensionErrorHandler.Exceptions; + if (exceptions.Count > 0) + { + throw new AggregateException("Extensions threw unexpected exceptions", exceptions); + } + base.Dispose(finalize); }