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

validate shape of packages.config and consolidate error handling #11303

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

brettfo
Copy link
Contributor

@brettfo brettfo commented Jan 14, 2025

Validate the shape of packages.config when first opening the file

Fixes #11250.

During this I realized that we had way too many ways to represent errors and to convert them, so everything was consolidated into a single function JobErrorBase.ErrorFromException(). Everything else is just calling this helper and updating the tests.

@brettfo brettfo requested a review from a team as a code owner January 14, 2025 21:04
@github-actions github-actions bot added the L: dotnet:nuget NuGet packages via nuget or dotnet label Jan 14, 2025
var invalidPackageElements = Packages.Where(p => p.GetAttribute("id") is null || p.GetAttribute("version") is null).ToList();
if (invalidPackageElements.Any())
{
throw new UnparseableFileException("`package` element missing `id` or `version` attributes", path);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was the fix for the linked issue.

@@ -14,4 +19,23 @@ public JobErrorBase(string type)

[JsonPropertyName("error-details")]
public Dictionary<string, object> Details { get; init; } = new();

public static JobErrorBase ErrorFromException(Exception ex, string jobId, string currentDirectory)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the consolidated error conversion.

@brettfo brettfo force-pushed the dev/brettfo/nuget-packages-config-parse branch from 76180a5 to d33f8e1 Compare January 14, 2025 23:52
@brettfo brettfo force-pushed the dev/brettfo/nuget-packages-config-parse branch from d33f8e1 to 1950ee9 Compare January 15, 2025 00:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
L: dotnet:nuget NuGet packages via nuget or dotnet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NuGet updater missing chance to return DependencyFileNotParseable
1 participant