New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unhelpful error when #loading a missing nuget package #2249

Closed
flcdrg opened this Issue Aug 22, 2018 · 5 comments

Comments

Projects
None yet
5 participants
@flcdrg
Copy link
Contributor

flcdrg commented Aug 22, 2018

What You Are Seeing?

Preparing to run build script...
Running build script...
C:/tmp/caketest/build.cake:1: One or more errors occurred.
Error: Errors occured while analyzing script.

What is Expected?

A specific error message that tells the end user what is wrong. In this case, the fact that the NuGet package that build.cake is trying to #load doesn't exist (because the version number is no longer available).

We had this problem happen recently where our own internal Recipe package (maintained on a TeamCity build server) had incremented to newer versions and the version referenced from a project no longer existed in the NuGet feed. The developer was confused as to what they'd done wrong (nothing at all as it turns out - someone else had probably forgot to pin the version build), and the error message didn't give any clues.

What version of Cake are you using?

0.3.0

Are you running on a 32 or 64 bit system?

64

What environment are you running on? Windows? Linux? Mac?

Windows

How Did You Get This To Happen? (Steps to Reproduce)

Create build.cake with the following content

#load nuget:?package=Cake.Recipe&version=0.1.0

Run standard build.ps1 bootstrapper

Output Log

Preparing to run build script...
Running build script...
Module directory does not exist.
NuGet.config not found.
Analyzing build script...
Analyzing C:/tmp/caketest/build.cake...
Missing C:\Users\David.nuget\packages\cake.recipe\0.1.0\cake.recipe.0.1.0.nupkg
CACHE https://api.nuget.org/v3/registration3-gz-semver2/cake.recipe/index.json
Missing C:\Users\David.nuget\packages\cake.recipe\0.1.0\cake.recipe.0.1.0.nupkg
C:/tmp/caketest/build.cake:1: One or more errors occurred.
Error: Cake.Core.CakeException: Errors occured while analyzing script.
at Cake.Core.Scripting.ScriptRunner.Run(IScriptHost host, FilePath scriptPath, IDictionary`2 arguments)
at Cake.Commands.BuildCommand.Execute(CakeOptions options)
at Cake.CakeApplication.Run(CakeOptions options)
at Cake.Program.Main()

@AlbertoMonteiro

This comment has been minimized.

Copy link

AlbertoMonteiro commented Sep 3, 2018

When I add &version=0.1.0 parameter starts to fail

@flcdrg

This comment has been minimized.

Copy link
Contributor

flcdrg commented Oct 5, 2018

@AlbertoMonteiro that's correct. If the version number doesn't actually exist (or it used to exist, but no longer does) on the relevant NuGet package feed, then that's the scenario that I'm describing.

@fseegraeber

This comment has been minimized.

Copy link
Contributor

fseegraeber commented Dec 15, 2018

The "One or more errors occurred." message comes from an AggregateException here, where an async method is called syncronously and the underlying exception gets wrapped.

// First get the install actions.
// This will give us the list of packages to install, and which feed should be used.
var actions = packageManager.GetInstallProjectActionsAsync(
project,
packageIdentity,
resolutionContext,
projectContext,
sourceRepositoryProvider.GetPrimaryRepositories(),
sourceRepositoryProvider.GetRepositories(),
CancellationToken.None).Result;

To actually provide the message from the exception thrown in the called async method, that call could be made with .ConfigureAwait(false).GetAwaiter().GetResult();

@flcdrg

This comment has been minimized.

Copy link
Contributor

flcdrg commented Dec 15, 2018

Sounds good.. Not sure if AggregateException.Flatten() could be useful here too.

@flcdrg

This comment has been minimized.

Copy link
Contributor

flcdrg commented Dec 15, 2018

Just tried @fseegraeber's suggestion, and it works a treat.. Here's the output with that change:

C:/dev/git/cake-version-test/build.cake:1: Unable to find version '1.2.3' of package 'Cake.Foo'.
Error: Errors occurred while analyzing script.

flcdrg added a commit to flcdrg/cake that referenced this issue Dec 15, 2018

Call GetAwaiter().GetResult()
- Avoids any exceptions being wrapped in AggregateException, which results in end-user getting the actual underlying error displayed should an exception being thrown

Fixes cake-build#2249

@devlead devlead added this to the v0.32.0 milestone Dec 19, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment