Skip to content
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

Log when Restore gets an HTTP 404 for a version when the package is listed on the feed #5845

Merged
merged 4 commits into from
Jun 10, 2024

Conversation

donnie-msft
Copy link
Contributor

@donnie-msft donnie-msft commented Jun 7, 2024

Bug

Fixes: NuGet/Home#13460

Regression? Last working version:

Description

I've tested Kartheek's branch, and since he's got higher priority issues right now, wanted to create the PR on his behalf.

What I've found is that, Azure DevOps (ADO) with upstream sources can return a 404 (not a 401) when a package exists but ADO permissions are not granted to the user to save the requested package version to the local feed.

My testing shows adding this simple logging is extremely useful as it provides a message to help a customer diagnose where the feed failed to find a package.

Normal verbosity

With normal verbosity,
Old behavior: MSB4181: The "Restore Task" task returned false but did not log an error.
New behavior :

C:\Program Files\Microsoft Visual Studio\2022\IntPreview\Common7\IDE\CommonExtensions\Microsoft\NuGet\NuGet.targets(170
,5): error : The feed 'my-test [https://pkgs.dev.azure.com/azure-public/vside/_packaging/my-test/nuget/v3/i
ndex.json]' lists package 'Microsoft.VisualStudio.ProjectSystem.Analyzers.17.10.221' but multiple attempts to download
the nupkg have failed. The feed is either invalid or required packages were removed while the current operation was in
progress. Verify the package exists on the feed and try again. [C:\apps\Prototypes\ListViewSample\ListViewSample.sln]

Detailed verbosity

With detailed verbosity, the error message is shown immediately after the full URL.
image

PR Checklist

  • PR has a meaningful title

  • PR has a linked issue.

  • Described changes

  • Tests

    • Automated tests added
    • OR
    • Test exception
    • OR
    • N/A
  • Documentation

    • Documentation PR or issue filled
    • OR
    • N/A

@donnie-msft donnie-msft requested a review from a team as a code owner June 7, 2024 21:07
@donnie-msft donnie-msft changed the title Dev kmps log error whenpackageisnotfound Log when Restore gets a 404 for a version of a package that is listed on the feed Jun 7, 2024
@donnie-msft donnie-msft changed the title Log when Restore gets a 404 for a version of a package that is listed on the feed Log when Restore gets an HTTP 404 for a version when the package is listed on the feed Jun 7, 2024
@kartheekp-ms
Copy link
Contributor

Thanks a lot, @donnie-msft, for helping with the testing. I was not sure how to reproduce MSB4181: The "Restore Task" task returned false but did not log an error in the tests to ensure that my change actually works and no longer raises this error. Your testing gave me confidence that the change will work as expected once it is integrated into dotnet, msbuild, etc.

@@ -91,6 +91,7 @@ public static class ResolverUtility
Strings.Error_PackageNotFoundWhenExpected,
match.Provider.Source,
ex.PackageIdentity.ToString());
context.Logger.LogError(message);
Copy link
Contributor

@kartheekp-ms kartheekp-ms Jun 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks to @nkolev92 for providing pointers to the code in NuGet/Home#13460 (comment). The detailed information really helped to understand the root cause of the bug.

There was one statement in that linked comment that I thought I could explain here:

Not sure why InvalidCacheProtocolException in particular gets ignored.

From what I understand, looking at the code, InvalidCacheProtocolException is ignored here because the caller ResolverUtility.FindLibraryEntryAsync has logic to try downloading the package twice. The first time when PackageNotFoundProtocolException is thrown, the code in the first catch block at the caller invalidates the cache and does a retry. That's why the exception is not logged at the callee but instead logged at the caller.

Hence, in this PR, the exception is logged to the logger at the caller in the second catch block that handles the PackageNotFoundProtocolException.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is missing a log code.
It should've probably been NU1301 like the other ones, or potentially a new one.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking about it more, this scenario is distinct enough, where I think it could use a separate code.

@donnie-msft donnie-msft requested a review from kartheekp-ms June 7, 2024 21:58
kartheekp-ms
kartheekp-ms previously approved these changes Jun 7, 2024
jeffkl
jeffkl previously approved these changes Jun 10, 2024
Copy link
Contributor

@jebriede jebriede left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving with minor suggestion about test name.

jebriede
jebriede previously approved these changes Jun 10, 2024
@donnie-msft donnie-msft dismissed stale reviews from jebriede, jeffkl, and kartheekp-ms via f8a6d84 June 10, 2024 18:14
@donnie-msft donnie-msft enabled auto-merge (squash) June 10, 2024 19:02
@donnie-msft donnie-msft merged commit de9c314 into dev Jun 10, 2024
27 of 28 checks passed
@donnie-msft donnie-msft deleted the dev-kmps-log-error-whenpackageisnotfound branch June 10, 2024 22:46
nkolev92 added a commit that referenced this pull request Jun 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MSB4181: The "Restore Task" task returned false but did not log an error.
5 participants