提交 7bae6740 编写于 作者: C CyrusNajmabadi

Report exceptions we encounter in the package search update service.

上级 d0882623
......@@ -23,26 +23,21 @@ public static T PerformIO<T>(Func<T> function, T defaultValue = default(T))
{
return function();
}
catch (IOException)
{
}
catch (SecurityException)
{
}
catch (ArgumentException)
{
}
catch (UnauthorizedAccessException)
{
}
catch (NotSupportedException)
{
}
catch (InvalidOperationException)
catch (Exception e) when (IsNormalIOException(e))
{
}
return defaultValue;
}
public static bool IsNormalIOException(Exception e)
{
return e is IOException ||
e is SecurityException ||
e is ArgumentException ||
e is UnauthorizedAccessException ||
e is NotSupportedException ||
e is InvalidOperationException;
}
}
}
}
\ No newline at end of file
......@@ -62,7 +62,7 @@ internal partial class PackageSearchService
private readonly IPackageSearchRemoteControlService _remoteControlService;
private readonly IPackageSearchPatchService _patchService;
private readonly IPackageSearchDatabaseFactoryService _databaseFactoryService;
private readonly Func<Exception, bool> _swallowException;
private readonly Func<Exception, bool> _reportAndSwallowException;
public void Dispose()
{
......@@ -212,7 +212,7 @@ private async Task<TimeSpan> UpdateDatabaseInBackgroundWorkerAsync()
// Just allow our caller to handle this (they will use this to stop their loop).
throw;
}
catch (Exception e) when (_service._swallowException(e))
catch (Exception e) when (_service._reportAndSwallowException(e))
{
// Something bad happened (IO Exception, network exception etc.).
// ask our caller to try updating again a minute from now.
......@@ -222,7 +222,7 @@ private async Task<TimeSpan> UpdateDatabaseInBackgroundWorkerAsync()
// down.
var delay = _service._delayService.UpdateFailedDelay;
_service.LogException(e, $"Error occurred updating. Retrying update in {delay}");
return _service._delayService.UpdateFailedDelay;
return delay;
}
}
......@@ -346,7 +346,7 @@ private async Task<TimeSpan> PatchLocalDatabaseAsync()
{
database = CreateAndSetInMemoryDatabase(databaseBytes);
}
catch (Exception e) when (_service._swallowException(e))
catch (Exception e) when (_service._reportAndSwallowException(e))
{
_service.LogException(e, "Error creating database from local copy. Downloading full database");
return await DownloadFullDatabaseAsync().ConfigureAwait(false);
......@@ -395,7 +395,7 @@ private async Task<TimeSpan> ProcessPatchXElementAsync(XElement patchElement, by
// Fall through and download full database.
}
catch (Exception e) when (_service._swallowException(e))
catch (Exception e) when (_service._reportAndSwallowException(e))
{
_service.LogException(e, "Error occurred while processing patch element. Downloading full database");
// Fall through and download full database.
......@@ -560,10 +560,17 @@ private async Task RepeatIOAsync(Action action)
try
{
action();
return;
}
catch (Exception e) when (_service._swallowException(e))
catch (Exception e)
{
// Normal IO exception. Don't bother reporting it. We don't want to get
// lots of hits just because we couldn't write a file because of something
// like an anti-virus tool lockign the file.
if (!IOUtilities.IsNormalIOException(e))
{
_service._reportAndSwallowException(e);
}
var delay = _service._delayService.FileWriteDelay;
_service.LogException(e, $"Operation failed. Trying again after {delay}");
await Task.Delay(delay, _service._cancellationToken).ConfigureAwait(false);
......
......@@ -11,6 +11,7 @@
using Microsoft.CodeAnalysis.Elfie.Model;
using Microsoft.CodeAnalysis.Elfie.Model.Structures;
using Microsoft.CodeAnalysis.Elfie.Model.Tree;
using Microsoft.CodeAnalysis.ErrorReporting;
using Microsoft.CodeAnalysis.Packaging;
using Microsoft.Internal.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.Settings;
......@@ -41,8 +42,8 @@ public PackageSearchService(VSShell.SVsServiceProvider serviceProvider, IPackage
new PatchService(),
new DatabaseFactoryService(),
new ShellSettingsManager(serviceProvider).GetApplicationDataFolder(ApplicationDataFolder.LocalSettings),
// swallow all exceptions
e => true,
// Report all exceptions we encounter, but don't crash on them.
FatalError.ReportWithoutCrash,
new CancellationTokenSource())
{
installerService.PackageSourcesChanged += OnPackageSourcesChanged;
......@@ -73,7 +74,7 @@ private static IPackageSearchRemoteControlService CreateRemoteControlService(VSS
IPackageSearchPatchService patchService,
IPackageSearchDatabaseFactoryService databaseFactoryService,
string localSettingsDirectory,
Func<Exception, bool> swallowException,
Func<Exception, bool> reportAndSwallowException,
CancellationTokenSource cancellationTokenSource)
{
if (remoteControlService == null)
......@@ -89,7 +90,7 @@ private static IPackageSearchRemoteControlService CreateRemoteControlService(VSS
_remoteControlService = remoteControlService;
_patchService = patchService;
_databaseFactoryService = databaseFactoryService;
_swallowException = swallowException;
_reportAndSwallowException = reportAndSwallowException;
_cacheDirectoryInfo = new DirectoryInfo(Path.Combine(
localSettingsDirectory, "PackageCache", string.Format(Invariant($"Format{_dataFormatVersion}"))));
......
......@@ -43,7 +43,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.Packaging
patchService:=Nothing,
databaseFactoryService:=Nothing,
localSettingsDirectory:="TestDirectory",
swallowException:=s_allButMoqExceptions,
reportAndSwallowException:=s_allButMoqExceptions,
cancellationTokenSource:=cancellationTokenSource)
Await service.UpdateSourceInBackgroundAsync(PackageSearchService.NugetOrgSource)
......@@ -73,7 +73,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.Packaging
patchService:=Nothing,
databaseFactoryService:=Nothing,
localSettingsDirectory:="TestDirectory",
swallowException:=s_allButMoqExceptions,
reportAndSwallowException:=s_allButMoqExceptions,
cancellationTokenSource:=cancellationTokenSource)
Await service.UpdateSourceInBackgroundAsync(PackageSearchService.NugetOrgSource)
......@@ -110,7 +110,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.Packaging
patchService:=Nothing,
databaseFactoryService:=Nothing,
localSettingsDirectory:="TestDirectory",
swallowException:=s_allButMoqExceptions,
reportAndSwallowException:=s_allButMoqExceptions,
cancellationTokenSource:=cancellationTokenSource)
Await searchService.UpdateSourceInBackgroundAsync(PackageSearchService.NugetOrgSource)
......@@ -144,7 +144,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.Packaging
patchService:=Nothing,
databaseFactoryService:=Nothing,
localSettingsDirectory:="TestDirectory",
swallowException:=s_allButMoqExceptions,
reportAndSwallowException:=s_allButMoqExceptions,
cancellationTokenSource:=cancellationTokenSource)
Await searchService.UpdateSourceInBackgroundAsync(PackageSearchService.NugetOrgSource)
......@@ -192,7 +192,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.Packaging
patchService:=Nothing,
databaseFactoryService:=Nothing,
localSettingsDirectory:="TestDirectory",
swallowException:=s_allButMoqExceptions,
reportAndSwallowException:=s_allButMoqExceptions,
cancellationTokenSource:=cancellationTokenSource)
Await searchService.UpdateSourceInBackgroundAsync(PackageSearchService.NugetOrgSource)
......@@ -235,7 +235,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.Packaging
patchService:=Nothing,
databaseFactoryService:=factoryMock.Object,
localSettingsDirectory:="TestDirectory",
swallowException:=s_allButMoqExceptions,
reportAndSwallowException:=s_allButMoqExceptions,
cancellationTokenSource:=cancellationTokenSource)
Await searchService.UpdateSourceInBackgroundAsync(PackageSearchService.NugetOrgSource)
......@@ -282,7 +282,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.Packaging
patchService:=Nothing,
databaseFactoryService:=factoryMock.Object,
localSettingsDirectory:="TestDirectory",
swallowException:=s_allButMoqExceptions,
reportAndSwallowException:=s_allButMoqExceptions,
cancellationTokenSource:=cancellationTokenSource)
Await searchService.UpdateSourceInBackgroundAsync(PackageSearchService.NugetOrgSource)
......@@ -340,7 +340,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.Packaging
patchService:=Nothing,
databaseFactoryService:=factoryMock.Object,
localSettingsDirectory:="TestDirectory",
swallowException:=s_allButMoqExceptions,
reportAndSwallowException:=s_allButMoqExceptions,
cancellationTokenSource:=cancellationTokenSource)
Await searchService.UpdateSourceInBackgroundAsync(PackageSearchService.NugetOrgSource)
......@@ -385,7 +385,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.Packaging
patchService:=Nothing,
databaseFactoryService:=databaseFactoryMock.Object,
localSettingsDirectory:="TestDirectory",
swallowException:=s_allButMoqExceptions,
reportAndSwallowException:=s_allButMoqExceptions,
cancellationTokenSource:=cancellationTokenSource)
Await searchService.UpdateSourceInBackgroundAsync(PackageSearchService.NugetOrgSource)
......@@ -438,7 +438,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.Packaging
patchService:=Nothing,
databaseFactoryService:=databaseFactoryMock.Object,
localSettingsDirectory:="TestDirectory",
swallowException:=s_allButMoqExceptions,
reportAndSwallowException:=s_allButMoqExceptions,
cancellationTokenSource:=cancellationTokenSource)
Await searchService.UpdateSourceInBackgroundAsync(PackageSearchService.NugetOrgSource)
......@@ -497,7 +497,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.Packaging
patchService:=Nothing,
databaseFactoryService:=databaseFactoryMock.Object,
localSettingsDirectory:="TestDirectory",
swallowException:=s_allButMoqExceptions,
reportAndSwallowException:=s_allButMoqExceptions,
cancellationTokenSource:=cancellationTokenSource)
Await searchService.UpdateSourceInBackgroundAsync(PackageSearchService.NugetOrgSource)
......@@ -552,7 +552,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.Packaging
patchService:=patchMock.Object,
databaseFactoryService:=databaseFactoryMock.Object,
localSettingsDirectory:="TestDirectory",
swallowException:=s_allButMoqExceptions,
reportAndSwallowException:=s_allButMoqExceptions,
cancellationTokenSource:=cancellationTokenSource)
Await searchService.UpdateSourceInBackgroundAsync(PackageSearchService.NugetOrgSource)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册