diff --git a/source/Cake.ExtendedNuGet.Tests/ExtendedNuGetTests.cs b/source/Cake.ExtendedNuGet.Tests/ExtendedNuGetTests.cs index ee66de2..79ceb77 100644 --- a/source/Cake.ExtendedNuGet.Tests/ExtendedNuGetTests.cs +++ b/source/Cake.ExtendedNuGet.Tests/ExtendedNuGetTests.cs @@ -69,6 +69,18 @@ public void IsNuGetPublishedAltSrcShouldBeFalse () Assert.False (p); } + [Fact] + public void IsNugetPublishedInvalidSourceShouldBeFalse () + { + var p = context.CakeContext.IsNuGetPublished ( + "Xamarin.Android.Support.v4", + "23.1.1.0", + "https://api.nuget.org/v3/wrong.json" + ); + + Assert.False (p); + } + [Fact] public void NuGetPackageIdFromFile () { diff --git a/source/Cake.ExtendedNuGet/ExtendedNuGetAliases.cs b/source/Cake.ExtendedNuGet/ExtendedNuGetAliases.cs index a18d50c..bceed38 100644 --- a/source/Cake.ExtendedNuGet/ExtendedNuGetAliases.cs +++ b/source/Cake.ExtendedNuGet/ExtendedNuGetAliases.cs @@ -16,6 +16,9 @@ using NuGet.Protocol.Core.Types; using NuGet.Versioning; +using LogLevel = Cake.Core.Diagnostics.LogLevel; +using Verbosity = Cake.Core.Diagnostics.Verbosity; + namespace Cake.ExtendedNuGet { /// @@ -112,18 +115,21 @@ public static bool IsNuGetPublished(this ICakeContext context, string packageId, Task.Run(async () => { - var nuSource = Repository.Factory.GetCoreV3(nugetSource); - using var nuCache = new SourceCacheContext(); - var nuLogger = NullLogger.Instance; - var pkgRes = await nuSource.GetResourceAsync(); - try { + var nuSource = Repository.Factory.GetCoreV3(nugetSource); + using var nuCache = new SourceCacheContext(); + var nuLogger = NullLogger.Instance; + + var pkgRes = await nuSource.GetResourceAsync(); var pkgInfo = await pkgRes.GetDependencyInfoAsync(packageId, new NuGetVersion(version.ToString()), nuCache, nuLogger, default); tcsPublished.TrySetResult(pkgInfo?.PackageIdentity?.Id?.Equals(packageId, StringComparison.OrdinalIgnoreCase) ?? false); } - catch + catch(Exception ex) { + context.Log.Write(Verbosity.Diagnostic, LogLevel.Error, + $"Failed to read nuget source repository information: {ex.Message}"); + tcsPublished.TrySetResult(false); } });