-
Notifications
You must be signed in to change notification settings - Fork 706
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 NU1105 error for badly specified framework #6291
base: dev
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, not my area of expertise. Could you provide a screenshot of what the command prompt showed before your change?
src/NuGet.Core/NuGet.Commands/RestoreCommand/Utility/SpecValidationUtility.cs
Outdated
Show resolved
Hide resolved
test/NuGet.Core.Tests/NuGet.Commands.Test/SpecValidationUtilityTests.cs
Outdated
Show resolved
Hide resolved
test/NuGet.Core.Tests/NuGet.Commands.Test/SpecValidationUtilityTests.cs
Outdated
Show resolved
Hide resolved
|
||
if (invalidFrameworks.Count > 0) | ||
{ | ||
throw RestoreSpecException.Create("", files); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm assuming the "" will be replaced with some new message that says in a generic way that one or more frameworks were invalid?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was on purpose. The logging of the error is done using an ilogger in a previous line.
The exception would look like
error : Invalid restore input. Input files: N:\trash\p7\p7\p7.csproj.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're throwing, there's still reason to put a message that makes sense into that exception, regardless of logging that may have happened.
An empty string here can result in an odd message with 2 periods like "Invalid restore input. ."
See:
NuGet.Client/src/NuGet.Core/NuGet.Commands/RestoreCommand/RequestFactory/RestoreSpecException.cs
Line 55 in dd3572a
completeMessage = string.Format( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that would happen
<data name="InvalidRestoreInput" xml:space="preserve"> |
If we were to put a message in the exception, it would look something like
NU1105: Invalid framework: ".9"
NU1105: Invalid framework: "unsupp1orted"
NU1105: Invalid framework: "1.222"
error : Invalid restore input. One or more invalid frameworks were detected. Input files: N:\trash\p7\p7\p7.csproj.
If we leave it as an empty message, it will look like
NU1105: Invalid framework: ".9"
NU1105: Invalid framework: "unsupp1orted"
NU1105: Invalid framework: "1.222"
error : Invalid restore input. Input files: N:\trash\p7\p7\p7.csproj.
Personally, I think adding the message again is redundent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're referencing 2 strings here. I'm only talking about InvalidRestoreInput
/// Looks up a localized string similar to Invalid restore input. {0}. |
When this message
is an empty string, I expect "Invalid restore input.__" where __ represents 2 unnecessary spaces.
This does not have "Input files:" in the string.
That would be InvalidRestoreInputWithFiles
. Again, I expect the empty string message to create this message: "Invalid restore input.___Input files: {1}." where ___ represents 3 unnecessary spaces and {1} is filled in with filenames.
I'm not following why it's good to omit the message in the exception. I don't think typically we say that logging a message means an exception should be generalized or with empty messages. It may be redundant but is there an issue with such redundancy?
src/NuGet.Core/NuGet.Commands/RestoreCommand/Utility/SpecValidationUtility.cs
Outdated
Show resolved
Hide resolved
src/NuGet.Core/NuGet.Commands/RestoreCommand/Utility/SpecValidationUtility.cs
Outdated
Show resolved
Hide resolved
src/NuGet.Core/NuGet.Commands/RestoreCommand/Utility/SpecValidationUtility.cs
Outdated
Show resolved
Hide resolved
src/NuGet.Core/NuGet.Commands/RestoreCommand/Utility/SpecValidationUtility.cs
Outdated
Show resolved
Hide resolved
src/NuGet.Core/NuGet.Commands/RestoreCommand/Utility/SpecValidationUtility.cs
Outdated
Show resolved
Hide resolved
src/NuGet.Core/NuGet.Commands/RestoreCommand/Utility/SpecValidationUtility.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thx for addressing my earlier comments!
src/NuGet.Core/NuGet.Commands/RestoreCommand/Utility/SpecValidationUtility.cs
Show resolved
Hide resolved
test/NuGet.Core.Tests/NuGet.Commands.Test/SpecValidationUtilityTests.cs
Outdated
Show resolved
Hide resolved
src/NuGet.Core/NuGet.Commands/RestoreCommand/Utility/SpecValidationUtility.cs
Outdated
Show resolved
Hide resolved
List<NuGetFramework> frameworkNames = new List<NuGetFramework>(spec.TargetFrameworks.Count); | ||
|
||
foreach (var f in spec.TargetFrameworks) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would combine the foreach
and only loop through the list once. Its okay to create a list with more items than you end up using. This that case it might make a list with 3 items but only add 2, then after the foreach
its just going to throw. But .NET would know that a list with a capacity of 3 really only has 2 items in it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, can you rename f
here please.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would combine the
foreach
and only loop through the list once. Its okay to create a list with more items than you end up using. This that case it might make a list with 3 items but only add 2, then after theforeach
its just going to throw. But .NET would know that a list with a capacity of 3 really only has 2 items in it.
The second loop is there in hopes of avoiding allocation since we might throw an exception if an invalid framework is found. That way, we don’t allocate a list unless we know we need it. However, given that the list is small, the extra allocation is negligible, and I don’t mind switching to one loop either.
Out of curiosity, have you tested how Visual Studio behaves here? |
Bug
Related: NuGet/Home#12943
Description
Ensure misconfigured projects (specifically projects with badly specified framework) fail with a coded error (NU1105), improving error clarity and debugging
Test project
Before
After
PR Checklist