private async Task LogWarningAsync(string id, FatalProtocolException e) { if (!_ignoreWarning) { await _logger.LogAsync(RestoreLogMessage.CreateWarning(NuGetLogCode.NU1801, e.Message, id)); } }
public async Task FindLibraryAsync_WhenASourceIsInaccessible_AndFailuresAreIgnored_EveryCallLogsAnErrorMessage() { // Arrange var cacheContext = new SourceCacheContext(); var expectedException = new FatalProtocolException("The source cannot be accessed"); var findResource = new Mock <FindPackageByIdResource>(); findResource.Setup(s => s.DoesPackageExistAsync( It.IsAny <string>(), It.IsAny <NuGetVersion>(), It.IsAny <SourceCacheContext>(), It.IsAny <ILogger>(), It.IsAny <CancellationToken>())) .Throws(expectedException); var source = new Mock <SourceRepository>(); source.Setup(s => s.GetResourceAsync <FindPackageByIdResource>()) .ReturnsAsync(findResource.Object); source.SetupGet(s => s.PackageSource) .Returns(new PackageSource("http://test/index.json")); var firstTestLogger = new TestLogger(); var secondTestLogger = new TestLogger(); var libraryRange = new LibraryRange("x", new VersionRange(new NuGetVersion(1, 0, 0)), LibraryDependencyTarget.Package); var provider = new SourceRepositoryDependencyProvider( source.Object, firstTestLogger, cacheContext, ignoreFailedSources: true, ignoreWarning: false); var results = await provider.FindLibraryAsync( new LibraryIdentity("x", NuGetVersion.Parse("1.0.0-beta"), LibraryType.Package), NuGetFramework.Parse("net45"), cacheContext, firstTestLogger, CancellationToken.None); // Pre-conditions - Assert results.Should().Be(null); firstTestLogger.WarningMessages.Should().HaveCount(1); firstTestLogger.ShowWarnings().Should().Contain("NU1801"); // Act results = await provider.FindLibraryAsync( new LibraryIdentity("x", NuGetVersion.Parse("1.0.0-beta"), LibraryType.Package), NuGetFramework.Parse("net45"), cacheContext, secondTestLogger, CancellationToken.None); // Assert results.Should().Be(null); secondTestLogger.WarningMessages.Should().HaveCount(1); secondTestLogger.ShowWarnings().Should().Contain("NU1801"); }
private async Task LogErrorAsync(ILogger logger, string id, FatalProtocolException e) { if (!_ignoreWarning) { // Sometimes, there's a better root cause for a source failures we log that instead of NU1301. // We only do this for errors, and not warnings. var unwrappedLogMessage = UnwrapToLogMessage(e); if (unwrappedLogMessage != null) { await logger.LogAsync(unwrappedLogMessage); } else { await logger.LogAsync(RestoreLogMessage.CreateError(NuGetLogCode.NU1301, e.Message, id)); } }
public async Task V2FeedParser_DuplicateNextUrl() { // Arrange var dupUrl = "https://www.nuget.org/api/v2/FindPackagesById?id='ravendb.client'&$skiptoken='RavenDB.Client','1.2.2067-Unstable'"; var serviceAddress = TestUtility.CreateServiceAddress(); var responses = new Dictionary <string, string>(); responses.Add(serviceAddress + "FindPackagesById()?id='ravendb.client'", TestUtility.GetResource("NuGet.Protocol.Core.v3.Tests.compiler.resources.CyclicDependency.xml", GetType())); responses.Add(serviceAddress, string.Empty); responses.Add(dupUrl, TestUtility.GetResource("NuGet.Protocol.Core.v3.Tests.compiler.resources.CyclicDependencyPage1.xml", GetType())); responses.Add("https://www.nuget.org/api/v2/FindPackagesById?id='ravendb.client'&$skiptoken='RavenDB.Client','2.0.2183-Unstable'", TestUtility.GetResource("NuGet.Protocol.Core.v3.Tests.compiler.resources.CyclicDependencyPage2.xml", GetType())); var httpSource = new TestHttpSource(new PackageSource(serviceAddress), responses); V2FeedParser parser = new V2FeedParser(httpSource, serviceAddress); FatalProtocolException duplicateUrlException = null; try { // Act var packages = await parser.FindPackagesByIdAsync("ravendb.client", NullLogger.Instance, CancellationToken.None); } catch (FatalProtocolException ex) { duplicateUrlException = ex; } // Assert Assert.NotNull(duplicateUrlException); Assert.Equal(string.Format(CultureInfo.CurrentCulture, Strings.Protocol_duplicateUri, dupUrl), duplicateUrlException.Message); }
public static bool HidesUnauthorizedError(this FatalProtocolException fatalProtocolException) { return(fatalProtocolException.Message.Contains("returned an unexpected status code '401 Unauthorized'")); }
public static bool HidesForbiddenError(this FatalProtocolException fatalProtocolException) { return(fatalProtocolException.Message.Contains("returned an unexpected status code '403 Forbidden'")); }